Addon for openFrameworks with bindings to the Duktape Javascript interpreter
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

README.md

ofxDuktape

openFrameworks addon with bindings to the Duktape Javascript interpreter

This addon is distributed under the terms of the MIT License.

Usage

#include "ofxDuktape.h"

// create a duktape context anywhere
ofxDuktape duk;

// use it in your code
int retcode = duk.pEval("log(\"hello openFrameworks!\"");

// pEval returns 0 if code was executed correctly, and other values for errors
if (!retcode) {
  // -1 is the index to the last object stored in duktape's stack, i.e. the result of the call
  ofLogInfo() << "return value is " << duk.safeToString(-1);
} else {
  ofLogError() << "error while executing javascript";
}

Extensions

The header file ofxDukOFBindings.h has most of openFrameworks 0.9 API implemented inside the of object, and a lot of syntactic sugar - ofSetXXX methods with single parameters and ofGetXXX methods are mostly implemented as properties

#include "ofxDukOFBindings.h"
ofxDuktape duk;

// setup the 'of' object in the javascript context
ofxDukBindings::setup(duk);

// interact with openFrameworks
duk.pEval("of.windowTitle = \"New window title\"");