Main /
DuktapeHostThe Duktape Host is a work in progress "Duktape is an embeddable Javascript engine, with a focus on portability and compact footprint." StatusThe Duktape host is an effort to run accessors in a very small memory footprint. The executable is under 300k. Under Mac OS X, using the Activity Monitor to inspect the
To get this data, I added a busy loop at the end of function sleepFor( sleepDuration ){ var now = new Date().getTime(); while(new Date().getTime() < now + sleepDuration){ /* do nothing */ } } sleepFor(20000); For hints about lowering the memory usage see
The current status is that accessors can be instantiated and run, but there is much to do. See Maxim Pegasus for running on a 512K RAM/2Mb Flash Cortex-M4. A Simple ExampleIn the example below, we compile the We then run Due to limitations about how Duktape handles relative paths in Note that the results is 50! bash-3.2$ cd accessors/web/hosts/duktape/duktape bash-3.2$ make clean rm -f duk bash-3.2$ make /Applications/Xcode.app/Contents/Developer/usr/bin/make -f Makefile.cmdline gcc -o duk -Os -pedantic -std=c99 -Wall -fstrict-aliasing -fomit-frame-pointer -I. -I./src \ -DDUK_OPT_SELF_TESTS src/duktape.c examples/cmdline/duk_cmdline.c examples/eventloop/fileio.c e\ xamples/eventloop/poll.c -lm bash-3.2$ ls -l duk -rwxr-xr-x 1 cxh staff 300376 Apr 26 14:21 duk bash-3.2$ cd ../.. bash-3.2$ ./duktape/duktape/duk --accessor --timeout 2000 duktape/test/testComposite.js duktapeHost.js done duk: About to instantiate duktape/test/testComposite.js timeout 2000 ../eduk/nofileio.c:163 Could not find ./duktape/test/testComposite.js ../eduk/nofileio.c:163 Could not find ../duktape/test/testComposite.js ../eduk/nofileio.c:163 Could not find ../../duktape/test/testComposite.js TestGain: input 10 gain: 4 TestAdder: inputLeft: 10 inputRight: 40 duktape/test/testComposite.js: OK: output was 50, which is equal to 50. bash-3.2$ Invoke Composite Accessor
See also Command Line Arguments. For example:
DebuggingCompile with DebuggingAdding the following to duktape.c and recompiling turns on debugging: #define DUK_USE_DEBUG 1 #define DUK_USE_DDPRINT 1 JSON.StringifyTo print the contents of an object in Duktape, download json2.js cd hosts/duktape wget https://raw.githubusercontent.com/douglascrockford/JSON-js/master/json2.js And then use code like: var json = require("duktape/json2"); console.log("commonHost is: " + JSON.stringify(commonHost)); See Also
|