All Projects → olebedev → Go Duktape

olebedev / Go Duktape

Licence: mit
Duktape JavaScript engine bindings for Go

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Go Duktape

Jsc.js
JavaScriptCore on WebAssembly
Stars: ✭ 311 (-58.37%)
Mutual labels:  javascript-engine
Emacs Tree Sitter
Tree-sitter for Emacs
Stars: ✭ 409 (-45.25%)
Mutual labels:  binding
Qtsharp
Mono/.NET bindings for Qt
Stars: ✭ 532 (-28.78%)
Mutual labels:  binding
Jni.hpp
A modern, type-safe, header-only, C++14 wrapper for JNI
Stars: ✭ 313 (-58.1%)
Mutual labels:  binding
G2opy
Python binding of SLAM graph optimization framework g2o
Stars: ✭ 360 (-51.81%)
Mutual labels:  binding
Store
Unidirectional, transactional, operation-based Store implementation.
Stars: ✭ 477 (-36.14%)
Mutual labels:  binding
Browser pwn
browser pwn, main work now
Stars: ✭ 293 (-60.78%)
Mutual labels:  javascript-engine
Leveldown
Pure C++ Node.js LevelDB binding. An abstract-leveldown compliant store.
Stars: ✭ 678 (-9.24%)
Mutual labels:  binding
Pyo3
Rust bindings for the Python interpreter
Stars: ✭ 5,110 (+584.07%)
Mutual labels:  binding
Hanson
Lightweight observations and bindings in Swift
Stars: ✭ 523 (-29.99%)
Mutual labels:  binding
V8
The official mirror of the V8 Git repository
Stars: ✭ 18,808 (+2417.8%)
Mutual labels:  javascript-engine
React Event Listener
A React component for binding events on the global scope. 💫
Stars: ✭ 359 (-51.94%)
Mutual labels:  binding
Pypostal
Python bindings to libpostal for fast international address parsing/normalization
Stars: ✭ 504 (-32.53%)
Mutual labels:  binding
Fritz2
Easily build reactive web-apps in Kotlin based on flows and coroutines.
Stars: ✭ 308 (-58.77%)
Mutual labels:  binding
Duktape
Duktape - embeddable Javascript engine with a focus on portability and compact footprint
Stars: ✭ 5,076 (+579.52%)
Mutual labels:  javascript-engine
Android Viewmodelbinding
A lightweight library aiming to speed up Android app development by leveraging the new Android Data Binding together with the Model-View-ViewModel design pattern.
Stars: ✭ 308 (-58.77%)
Mutual labels:  binding
Calcbinding
Advanced WPF Binding which supports expressions in Path property and other features
Stars: ✭ 425 (-43.11%)
Mutual labels:  binding
Cimgui
c-api for imgui (https://github.com/ocornut/imgui) Look at: https://github.com/cimgui for other widgets
Stars: ✭ 707 (-5.35%)
Mutual labels:  binding
Imgui Sfml
Dear ImGui binding for use with SFML
Stars: ✭ 596 (-20.21%)
Mutual labels:  binding
Iossampleapp
Sample iOS app demonstrating Coordinators, Dependency Injection, MVVM, Binding
Stars: ✭ 510 (-31.73%)
Mutual labels:  binding

Duktape bindings for Go(Golang)

wercker status Travis status Appveyor status Gitter

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

Usage

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

package main

import "fmt"
import "gopkg.in/olebedev/go-duktape.v3"

func main() {
  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 main

import "fmt"
import "gopkg.in/olebedev/go-duktape.v3"

func main() {
  ctx := duktape.New()
  ctx.PushGlobalGoFunction("log", func(c *duktape.Context) int {
    fmt.Println(c.SafeToString(-1))
    return 0
  })
  ctx.PevalString(`log('Go lang Go!')`)
}

then run it.

$ go run *.go
Go lang Go!
$

Timers

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

package main

import "fmt"
import "gopkg.in/olebedev/go-duktape.v3"

func main() {
  ctx := duktape.New()

  // Let's inject `setTimeout`, `setInterval`, `clearTimeout`,
  // `clearInterval` into global scope.
  ctx.PushTimers()

  ch := make(chan string)
  ctx.PushGlobalGoFunction("second", func(_ *Context) int {
    ch <- "second step"
    return 0
  })
  ctx.PevalString(`
    setTimeout(second, 0);
    print('first step');
  `)
  fmt.Println(<-ch)
}

then run it

$ go run *.go
first step
second step
$

Also you can FlushTimers().

Command line tool

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

Benchmarks

prog time
otto 200.13s
anko 231.19s
agora 149.33s
GopherLua 8.39s
go-duktape 9.80s

More details are here.

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].