Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
This repository was archived by the owner on Oct 29, 2021. It is now read-only.
/go-duktapePublic archive

[abandoned] Duktape JavaScript engine bindings for Go

License

NotificationsYou must be signed in to change notification settings

olebedev/go-duktape

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wercker statusTravis statusAppveyor statusGitter

Duktape is a thin, embeddable javascript engine.Most of theapi is implemented.The exceptions are listedhere.

Usage

The package is fully go-getable, no need to install any external C libraries.
So, just typego get gopkg.in/olebedev/go-duktape.v3 to install.

package mainimport"fmt"import"gopkg.in/olebedev/go-duktape.v3"funcmain() {ctx:=duktape.New()ctx.PevalString(`2 + 3`)result:=ctx.GetNumber(-1)ctx.Pop()fmt.Println("result is:",result)// To prevent memory leaks, don't forget to clean up after// yourself when you're done using a context.ctx.DestroyHeap()}

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 mainimport"fmt"import"gopkg.in/olebedev/go-duktape.v3"funcmain() {ctx:=duktape.New()ctx.PushGlobalGoFunction("log",func(c*duktape.Context)int {fmt.Println(c.SafeToString(-1))return0  })ctx.PevalString(`log('Go lang Go!')`)}

then run it.

$ go run*.goGo lang Go!$

Timers

There is a method to inject timers to the global scope:

package mainimport"fmt"import"gopkg.in/olebedev/go-duktape.v3"funcmain() {ctx:=duktape.New()// Let's inject `setTimeout`, `setInterval`, `clearTimeout`,// `clearInterval` into global scope.ctx.PushTimers()ch:=make(chanstring)ctx.PushGlobalGoFunction("second",func(_*Context)int {ch<-"second step"return0  })ctx.PevalString(`    setTimeout(second, 0);    print('first step');  `)fmt.Println(<-ch)}

then run it

$ go run*.gofirst stepsecond step$

Also you canFlushTimers().

Command line tool

Installgo get gopkg.in/olebedev/go-duktape.v3/....
Execute file.js:$GOPATH/bin/go-duk file.js.

Benchmarks

progtime
otto200.13s
anko231.19s
agora149.33s
GopherLua8.39s
go-duktape9.80s

More details arehere.

Status

The package is not fully tested, so be careful.

Contribution

Pull requests are welcome! Also, if you want to discuss something send a pull request with proposal and changes.Convention: fork the repository and make changes on your fork in a feature branch.

About

[abandoned] Duktape JavaScript engine bindings for Go

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp