Skip to content

Latest commit

 

History

History
55 lines (43 loc) · 1.33 KB

README.md

File metadata and controls

55 lines (43 loc) · 1.33 KB

Duktape bindings for Go(Golang) wercker status

Duktape is a thin, embeddable javascript engine. Most of the api is implemented. The exceptions are listed here.

Usage

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)
}

Go specific notes

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!

Status

The package is not fully tested, so be careful.

Contribution

Pull requests are welcome!
Convention: fork the repository and make changes on your fork in a feature branch.