tengo
tengo copied to clipboard
Call compiled function from go return empty
Hello! When call compiled function from go return empty.
package main
import (
"context"
"fmt"
"github.com/d5/tengo"
)
func main() {
// create a new Script instance
script := tengo.NewScript([]byte(`
res := wait_go_hello_message(func(message) {
return "Go Hello Message:" + message
})
`))
script.Add("wait_go_hello_message", func(args ...tengo.Object) (ret tengo.Object, err error) {
return args[0].(*tengo.CompiledFunction).Call(&tengo.String{Value: "hello!"})
})
// run the script
compiled, err := script.RunContext(context.Background())
if err != nil {
panic(err)
}
res := compiled.Get("res")
// EXPECTED: Go Hello Message: hello!
fmt.Printf("%T: %q", res, res) // OUTPUT: *tengo.Variable: ""
}
@moisespsena , Your usecase mixes builtin and compiled functions in a way that Tengo does not support. You can't Call into a compiled function directly. Look at #275 This is a duplicate issue.
@DawDavis , I have implemented a branch "vm_context" based on tengox with the definition of objects based on maps and reflection. I did it to be able to use it in my personal projects.
See to call tengo function from go.
What do you think?