Updated 2016-07-13 13:26:01 by dbohdan
What tcl-duktape
Where https://github.com/dbohdan/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 2016-05-16
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  edit

#!/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  edit