Last updated
Was this helpful?
Was this helpful?
func sum(x, y int64) int64 {
return x + 2*y
}
func varInt(init int64, pars ...int64) int64 {
for _, i := range pars {
init += i
}
return init
}
func shortLen(s string) (int64, error) {
if len(s) < 10 {
return len(s), nil
}
return 0, fmt.Errorf("string %s is too long", s)
}
func main() {
var customLib = []gentee.EmbedItem{
{Prototype: `sum(int,int) int`, Object: sum},
{Prototype: `InitSum(int) int`, Object: varInt},
{Prototype: `ShortLen(str) int`, Object: shortLen},
}
err := gentee.Customize(&gentee.Custom{
Embedded: customLib,
})
if err != nil {
log.Fatal(err)
}
workspace := gentee.New()
exec, _, err := workspace.Compile(`run {
Println("Sum = %{sum(10, 6)}")
Println("InitSum = " + InitSum(4, 67, 4, 22))
ShortLen("this string is too long")
}`, ``)
...
}