Version 6 of tcl-duktape

Updated 2017-02-04 15:47:09 by DDG
What tcl-duktape
Description A binary Tcl extension that proves bindings for Duktape, an embedded JavaScript interpreter.
Platforms Tested on Linux and FreeBSD.
Prerequisites Tcl 8.5 or newer, TclOO required for the OO wrapper.
Updated 2017-01-26
License MIT

Duktape is just a pair of .c/.h files, which makes the package easy to build. tcl-duktape allows you to call JavaScript code from Tcl and exposes a jsproc interface similar to the cproc interface in Critcl that allows you to write procedures in JavaScript. Included in the package is a TclOO API wrapper for tcl-duktape objects and one for JSON objects. No means to register Tcl callbacks to be called from JavaScript are currently provided.

Sample code

#!/usr/bin/env tclsh
package require duktape
package require duktape::oo

set duktapeObj [::duktape::oo::Duktape new]
$duktapeObj jsproc ::add {{a 0 number} {b 0 number}} {
    return a + b;
puts [add 1 2]
$duktapeObj jsmethod cos {{deg 0 number}} {
    return Math.cos(deg * Math.PI / 180);
puts [$duktapeObj cos 360]
$duktapeObj destroy

See also