H3D API
2.4.1
|
The SpiderMonkeySAI class is an implementation of the X3D Ecmascript SAI specification using SpiderMonkey(the Javascript engine used by Firefox) More...
#include <H3D/SpiderMonkeySAI.h>
Classes | |
class | CallbackFunctionDispatcher |
The CallbackFunctionDispatcher class handles the calls of the ecmascript callback functions for the fields. More... | |
Public Member Functions | |
SpiderMonkeySAI () | |
Constructor. | |
bool | initializeScriptEngine (Script *s) |
Initialize the script engine for the given script, adding all types, attributes, functions etc . More... | |
string | loadScript (const string &s, const string &filename) |
Run the script specified by s. More... | |
void | uninitializeScriptEngine () |
Release all resources allocated for the script engine. | |
bool | isInitialized () |
Returns true if the script engine has been initialized. | |
virtual bool | addField (Field *field) |
Add an interface to a field to the script engine. More... | |
Protected Member Functions | |
string | fieldNameToCallbackName (const string &n) |
Given a field name it returns the name used for the callback function in the global namespace. More... | |
Protected Attributes | |
JSRuntime * | rt |
The script engine runtime used. | |
JSContext * | cx |
The script engine context used. | |
JSObject * | global |
The global object including all global properties and functions. | |
Script * | script_node |
The Script node this script engine is used for,. | |
H3DUniquePtr< CallbackFunctionDispatcher > | callbackFunctionDispatcher |
Field that handles calling of callback functions as events are received. | |
The SpiderMonkeySAI class is an implementation of the X3D Ecmascript SAI specification using SpiderMonkey(the Javascript engine used by Firefox)
|
virtual |
Add an interface to a field to the script engine.
It will be added to the global namespace with the property name equal to the name of the field.
found ) {
References isInitialized().
Referenced by H3D::Script::addField(), and loadScript().
|
protected |
Given a field name it returns the name used for the callback function in the global namespace.
According to the Ecmascript X3D specification the callback function and the field property name should be the same. This is not possible in SpiderMonkey so we rename the callback function to the name returned by this function.
Referenced by loadScript().
bool SpiderMonkeySAI::initializeScriptEngine | ( | Script * | s | ) |
Initialize the script engine for the given script, adding all types, attributes, functions etc .
Needs to be called before any other function are called.
References cx, rt, and script_node.
string SpiderMonkeySAI::loadScript | ( | const string & | s, |
const string & | filename | ||
) |
Run the script specified by s.
s | A string with the script code to run. |
filename | A filename/identifier identifying the source of the string. Used for error messages. |
References addField(), cx, H3D::H3DDynamicFieldsObject::endField(), fieldNameToCallbackName(), H3D::H3DDynamicFieldsObject::firstField(), global, H3D::SpiderMonkey::haveFunction(), and script_node.