Skip to content

ivan4th/go-duktape

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Duktape JavaScript engine bindings for Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 98.0%
  • Go 2.0%