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 | 04/2015 |
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.
#!/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