This extension adds Node.js-like environment and embedded hardware support to Duktape (>= 2.x)
- ES6 features
- Promise (Not fully compatible to ECMA262 6th edition)
- Node.js-like environment
- Console
- Modules
- Path
- Process
- Timers
- Utilities
- Embedded hardware support for Rubic-compatible firmware (for example: olive)
- Hardware
- Peridot
- Download distribution package (duktape-extension-x.x.x.tar.gz) from releases
- Extract
dist
directory from downloaded archive - Copy extracted files to your C/C++ project
- Edit
dux_config.h
to customize duktape-extension
This extension has only several public functions:
dux_initialize()
: Initialize duktape-extension for specified Duktape context (duk_context
)dux_tick()
: Process tick routines for event loopdux_[p]eval_module_file[_noresult]()
: Load file as a module and evalulate itdux_[p]eval_module_[l]string[_noresult]()
: Load string (JavaScript) as a module and evaluate it
#include <duktape.h>
#include <dukext.h>
int main()
{
duk_context *ctx;
// Create Duktape heap
ctx = duk_create_heap_default();
// Initialize duktape-extension without file accessor
dux_initialize(ctx, NULL);
// Load main source
duk_eval_string_noresult(ctx, "setTimeout(function(){ console.log('hello world') }, 1000)");
// Start event loop
while (dux_tick(ctx)) {
// dux_tick returns true if there are any incomplete jobs
// You may insert some delays here to avoid busy loop
}
// Event loop finished
duk_destroy_heap(ctx);
// You don't need call any terminate function for duktape-extension.
// All resources of duktape-extension will be destroyed in duk_destroy_heap()
return 0;
}
The MIT license