Duktape is a thin, embeddable javascript engine. Most of the api is implemented. The exceptions are listed here.
package main
import "fmt"
import "github.com/olebedev/go-duktape"
func main() {
ctx := duktape.NewContext()
ctx.EvalString(`2 + 3`)
result := ctx.GetNumber(-1)
ctx.Pop()
fmt.Println("result is:", result)
}
Bindings between Go and Javascript contexts are not fully functional. However, binding a Go function to the Javascript context is available:
package main
import "fmt"
import "github.com/olebedev/go-duktape"
func main() {
ctx := duktape.NewContext()
ctx.PushGofunc("log", func(ctx *duktape.Context) int {
fmt.Println("Go lang Go!")
return 0
})
ctx.EvalString(`log()`)
}
than run it.
$ go run
$ Go lang Go!
The package is not fully tested, so be careful.
Pull requests are welcome!
Convention: fork the repository and make changes on your fork in a feature branch.