Cocos2d-x  v3.10
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups
JS Binding

Classes

class  ScriptingCore
 ScriptingCore is the main class which manages interaction with JavaScript environment It creates the JavaScript context and its global object. More...
 

Functions

static ScriptingCoregetInstance ()
 ScriptingCore is a singleton class, you can retrieve its instance with this function. More...
 
virtual cocos2d::ccScriptType getScriptType () override
 Gets the script type, for ScriptingCore, it will return cocos2d::kScriptTypeJavascript
 
local getScriptType ()
 Gets the script type, for ScriptingCore, it will return cocos2d::kScriptTypeJavascript
 
virtual void removeScriptObjectByObject (cocos2d::Ref *obj) override
 Removes the C++ object's linked JavaScript proxy object from JavaScript context Object to be removed.
 
local removeScriptObjectByObject ( local obj)
 Removes the C++ object's linked JavaScript proxy object from JavaScript context Object to be removed.
 
virtual int executeString (const char *codes) override
 Useless in ScriptingCore, please use evalString.
 
void pauseSchedulesAndActions (js_proxy_t *p)
 Pause scheduled tasks and actions for an object proxy. More...
 
var pauseSchedulesAndActions ( var p)
 Pause scheduled tasks and actions for an object proxy. More...
 
local pauseSchedulesAndActions ( local p)
 Pause scheduled tasks and actions for an object proxy. More...
 
void resumeSchedulesAndActions (js_proxy_t *p)
 Resume scheduled tasks and actions for an object proxy. More...
 
void cleanupSchedulesAndActions (js_proxy_t *p)
 Cleanup scheduled tasks and actions for an object proxy. More...
 
virtual int executeScriptFile (const char *filename) override
 Useless in ScriptingCore, please use runScript.
 
virtual int executeGlobalFunction (const char *functionName) override
 Useless in ScriptingCore, please use executeFunctionWithOwner.
 
virtual int sendEvent (cocos2d::ScriptEvent *message) override
 When some events triggered in the c++ also needs to pass into script ,call this func.The ScriptEvent contains the data need to passed into the script.
 
local sendEvent ( local message)
 When some events triggered in the c++ also needs to pass into script ,call this func.The ScriptEvent contains the data need to passed into the script.
 
virtual bool parseConfig (ConfigType type, const std::string &str) override
 Parse configuration file. More...
 
local parseConfig ( local type, local str)
 Parse configuration file. More...
 
virtual bool handleAssert (const char *msg) override
 Useless in ScriptingCore false.
 
var handleAssert ( var msg)
 Useless in ScriptingCore false.
 
local handleAssert ( local msg)
 Useless in ScriptingCore false.
 
virtual void setCalledFromScript (bool callFromScript) override
 Set whether the call comes from the script or not, only use for the js. More...
 
virtual bool isCalledFromScript () override
 Get the flag that represents whether the call comes from the script or not,only use for the js. More...
 
bool executeFunctionWithObjectData (void *nativeObj, const char *name, JSObject *obj)
 Execute a js function with a JavaScript object as parameter. More...
 
bool executeFunctionWithOwner (jsval owner, const char *name, uint32_t argc, jsval *vp)
 Execute a js function with a JavaScript caller, function name, arguments count and arguments. More...
 
bool executeFunctionWithOwner (jsval owner, const char *name, uint32_t argc, jsval *vp, JS::MutableHandleValue retVal)
 Execute a js function with a JavaScript caller, function name, arguments count, arguments and a return value. More...
 
bool executeFunctionWithOwner (jsval owner, const char *name, const JS::HandleValueArray &args)
 Execute a js function with a JavaScript caller, function name, arguments array. More...
 
bool executeFunctionWithOwner (jsval owner, const char *name, const JS::HandleValueArray &args, JS::MutableHandleValue retVal)
 Execute a js function with a JavaScript caller, function name, arguments array and a return value. More...
 
void executeJSFunctionWithThisObj (JS::HandleValue thisObj, JS::HandleValue callback)
 Execute a js function with a js this object and the js function object. More...
 
void executeJSFunctionWithThisObj (JS::HandleValue thisObj, JS::HandleValue callback, const JS::HandleValueArray &vp, JS::MutableHandleValue retVal)
 Execute a js function with a js this object, the js function object, arguments and a return value. More...
 
bool evalString (const char *string, JS::MutableHandleValue outVal, const char *filename, JSContext *cx, JS::HandleObject global)
 Evaluate the specified js code string The string with the javascript code to be evaluated The jsval that will hold the return value of the evaluation. More...
 
bool evalString (const char *string, JS::MutableHandleValue outVal)
 Evaluate the specified js code string. More...
 
bool evalString (const char *string)
 Evaluate the specified js code string. More...
 
JSScript * getScript (const char *path)
 Get script object for the given path The script file path Script object.
 
void compileScript (const char *path, JS::HandleObject global, JSContext *cx=NULL)
 Compile the specified js file The path of the script to to compiled The js global object The js context.
 
bool runScript (const char *path)
 Run the specified js file The path of the script to be executed Return true if succeed, otherwise return false.
 
bool runScript (const char *path, JS::HandleObject global, JSContext *cx=NULL)
 Run the specified js file The path of the script to be executed The global object to execute the script The context to execute the script Return true if succeed, otherwise return false.
 
local runScript ( local path, local global, local NULL)
 Run the specified js file The path of the script to be executed The global object to execute the script The context to execute the script Return true if succeed, otherwise return false.
 
bool requireScript (const char *path, JS::MutableHandleValue jsvalRet)
 Require the specified js file The difference between run and require is that require returns the export object of the script. More...
 
var requireScript ( var path, var jsvalRet)
 Require the specified js file The difference between run and require is that require returns the export object of the script. More...
 
local requireScript ( local path, local jsvalRet)
 Require the specified js file The difference between run and require is that require returns the export object of the script. More...
 
bool requireScript (const char *path, JS::HandleObject global, JSContext *cx, JS::MutableHandleValue jsvalRet)
 Require the specified js file The difference between run and require is that require returns the export object of the script. More...
 
void cleanScript (const char *path)
 Clean script object for the specified js file The path of the js file to be cleaned.
 
std::unordered_map
< std::string, JSScript * > & 
getFileScript ()
 Gets the cached script objects for all executed js file The cached script object map.
 
local getFileScript ()
 Gets the cached script objects for all executed js file The cached script object map.
 
void cleanAllScript ()
 Clean all script objects.
 
void start ()
 Initialize everything, including the js context, js global object etc.
 
void cleanup ()
 Cleanup everything, including script cache, js context, global object etc.
 
void reset ()
 Cleanup everything then initialize everything.
 
void addRegisterCallback (sc_register_sth callback)
 Add the register_sth callback to the list of functions that need to be called after the creation of the context. More...
 
void createGlobalContext ()
 Create a new context. More...
 
static void removeAllRoots (JSContext *cx)
 Removes all rooted object in the given js context, rooted object won't be garbage collected. More...
 
int executeCustomTouchEvent (cocos2d::EventTouch::EventCode eventType, cocos2d::Touch *pTouch, JSObject *obj, JS::MutableHandleValue retval)
 Simulate a touch event and dispatch it to a js object. More...
 
int executeCustomTouchEvent (cocos2d::EventTouch::EventCode eventType, cocos2d::Touch *pTouch, JSObject *obj)
 Simulate a touch event and dispatch it to a js object. More...
 
int executeCustomTouchesEvent (cocos2d::EventTouch::EventCode eventType, const std::vector< cocos2d::Touch * > &touches, JSObject *obj)
 Simulate a multi touch event and dispatch it to a js object. More...
 
JSContext * getGlobalContext ()
 Gets the current global context. More...
 
static void reportError (JSContext *cx, const char *message, JSErrorReport *report)
 Report an error in the js context The js context The error message The js error report object.
 
static bool log (JSContext *cx, uint32_t argc, jsval *vp)
 Log something to the js context using CCLog. More...
 
bool setReservedSpot (uint32_t i, JSObject *obj, jsval value)
 Sets a js value to the targeted js obejct's reserved slot, which is not exposed to script environment. More...
 
static bool executeScript (JSContext *cx, uint32_t argc, jsval *vp)
 Runs a script from script environment, it should be invoked from script environment Bound to __jsc__.executeScript and window.executeScript The js context The arguments count The arguments Return true if succeed, otherwise return false.
 
local executeScript ( local cx, local argc, local vp)
 Runs a script from script environment, it should be invoked from script environment Bound to __jsc__.executeScript and window.executeScript The js context The arguments count The arguments Return true if succeed, otherwise return false.
 
static bool forceGC (JSContext *cx, uint32_t argc, jsval *vp)
 Forces a cycle of garbage collection, it should be invoked from script environment Bound to __jsc__.garbageCollect and window.garbageCollect The js context The arguments count The arguments.
 
var forceGC ( var cx, var argc, var vp)
 Forces a cycle of garbage collection, it should be invoked from script environment Bound to __jsc__.garbageCollect and window.garbageCollect The js context The arguments count The arguments.
 
local forceGC ( local cx, local argc, local vp)
 Forces a cycle of garbage collection, it should be invoked from script environment Bound to __jsc__.garbageCollect and window.garbageCollect The js context The arguments count The arguments.
 
static bool dumpRoot (JSContext *cx, uint32_t argc, jsval *vp)
 Dump all named rooted objects, it should be invoked from script environment Bound to __jsc__.dumpRoot The js context The arguments count The arguments.
 
static bool addRootJS (JSContext *cx, uint32_t argc, jsval *vp)
 Adds a js object to root so that it won't be touched by the garbage collection, it should be invoked from script environment Bound to __jsc__.addGCRootObject The js context The arguments count The arguments.
 
static bool removeRootJS (JSContext *cx, uint32_t argc, jsval *vp)
 Removes a js object from root, it should be invoked from script environment Bound to __jsc__.removeGCRootObject The js context The arguments count The arguments.
 
static bool isObjectValid (JSContext *cx, uint32_t argc, jsval *vp)
 Check whether a js object's C++ proxy is still valid, it should be invoked from script environment Bound to window.__isObjectValid The js context The arguments count The arguments.
 
void debugProcessInput (const std::string &str)
 Log a string to the debug environment. More...
 
void enableDebugger (unsigned int port=5086)
 Enable the debug environment, mozilla Firefox's remote debugger or Code IDE can connect to it. More...
 
JSObject * getDebugGlobal ()
 Gets the debug environment's global object The debug environment's global object.
 
JSObject * getGlobalObject ()
 Gets the global object The global object.
 
bool isFunctionOverridedInJS (JS::HandleObject obj, const std::string &name, JSNative native)
 Checks whether a C++ function is overrided in js prototype chain The js object The function name The native function The global object.
 
virtual void rootObject (cocos2d::Ref *ref) override
 Roots the associated JSObj. More...
 
var rootObject ( var ref)
 Roots the associated JSObj. More...
 
local rootObject ( local ref)
 Roots the associated JSObj. More...
 
virtual void unrootObject (cocos2d::Ref *ref) override
 Unroots the associated JSObj. More...
 
local unrootObject ( local ref)
 Unroots the associated JSObj. More...
 
js_proxy_t * jsb_new_proxy (void *nativeObj, JS::HandleObject jsObj)
 creates two new proxies: one associaged with the nativeObj, and another one associated with the JsObj
 
js_proxy_t * jsb_get_native_proxy (void *nativeObj)
 returns the proxy associated with the Native*
 
js_proxy_t * jsb_get_js_proxy (JSObject *jsObj)
 returns the proxy associated with the JSObject*
 
void jsb_remove_proxy (js_proxy_t *nativeProxy, js_proxy_t *jsProxy)
 deprecated: use jsb_remove_proxy(js_proxy_t* proxy) instead
 
void jsb_remove_proxy (js_proxy_t *proxy)
 removes both the native and js proxies
 
void jsb_ref_init (JSContext *cx, JS::Heap< JSObject * > *obj, cocos2d::Ref *ref, const char *debug)
 Generic initialization function for subclasses of Ref.
 
void jsb_ref_autoreleased_init (JSContext *cx, JS::Heap< JSObject * > *obj, cocos2d::Ref *ref, const char *debug)
 Generic initialization function for subclasses of Ref. More...
 
void jsb_ref_finalize (JSFreeOp *fop, JSObject *obj)
 Generic finalize used by objects that are subclass of Ref.
 
void jsb_ref_rebind (JSContext *cx, JS::HandleObject jsobj, js_proxy_t *js2native_proxy, cocos2d::Ref *oldRef, cocos2d::Ref *newRef, const char *debug)
 Disassociates oldRef from jsobj, and associates a new Ref. More...
 
JSObject * jsb_ref_create_jsobject (JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char *debug)
 Creates a new JSObject of a certain type (typeClass) and creates a proxy associated with and the Ref.
 
JSObject * jsb_ref_autoreleased_create_jsobject (JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char *debug)
 Creates a new JSObject of a certain type (typeClass) and creates a proxy associated with and the Ref Similar to jsb_ref_create_jsobject(), but call it if you know that Ref has been autoreleased This function should never be called. More...
 
JSObject * jsb_ref_get_or_create_jsobject (JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char *debug)
 It will try to get the associated JSObjct for ref. More...
 
JSObject * jsb_ref_autoreleased_get_or_create_jsobject (JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char *debug)
 It will try to get the associated JSObjct for ref. More...
 

Detailed Description

Function Documentation

static ScriptingCore* getInstance ( )
static

ScriptingCore is a singleton class, you can retrieve its instance with this function.

The ScriptingCore instance.

var getInstance ( )
static

ScriptingCore is a singleton class, you can retrieve its instance with this function.

The ScriptingCore instance.

local getInstance ( )
static

ScriptingCore is a singleton class, you can retrieve its instance with this function.

The ScriptingCore instance.

void pauseSchedulesAndActions ( js_proxy_t *  p)

Pause scheduled tasks and actions for an object proxy.

The object proxy

var pauseSchedulesAndActions ( var  p)

Pause scheduled tasks and actions for an object proxy.

The object proxy

local pauseSchedulesAndActions ( local  p)

Pause scheduled tasks and actions for an object proxy.

The object proxy

void resumeSchedulesAndActions ( js_proxy_t *  p)

Resume scheduled tasks and actions for an object proxy.

The object proxy

var resumeSchedulesAndActions ( var  p)

Resume scheduled tasks and actions for an object proxy.

The object proxy

local resumeSchedulesAndActions ( local  p)

Resume scheduled tasks and actions for an object proxy.

The object proxy

void cleanupSchedulesAndActions ( js_proxy_t *  p)

Cleanup scheduled tasks and actions for an object proxy.

The object proxy

var cleanupSchedulesAndActions ( var  p)

Cleanup scheduled tasks and actions for an object proxy.

The object proxy

local cleanupSchedulesAndActions ( local  p)

Cleanup scheduled tasks and actions for an object proxy.

The object proxy

virtual bool parseConfig ( ConfigType  type,
const std::string &  str 
)
overridevirtual

Parse configuration file.

the specific type value. the information data.

Implements ScriptEngineProtocol.

var parseConfig ( var  type,
var  str 
)
overridevirtual

Parse configuration file.

the specific type value. the information data.

Implements ScriptEngineProtocol.

local parseConfig ( local  type,
local  str 
)
overridevirtual

Parse configuration file.

the specific type value. the information data.

Implements ScriptEngineProtocol.

virtual void setCalledFromScript ( bool  callFromScript)
inlineoverridevirtual

Set whether the call comes from the script or not, only use for the js.

whether the call comes from the script or not.

Reimplemented from ScriptEngineProtocol.

var setCalledFromScript ( var  callFromScript)
inlineoverridevirtual

Set whether the call comes from the script or not, only use for the js.

whether the call comes from the script or not.

Reimplemented from ScriptEngineProtocol.

local setCalledFromScript ( local  callFromScript)
inlineoverridevirtual

Set whether the call comes from the script or not, only use for the js.

whether the call comes from the script or not.

Reimplemented from ScriptEngineProtocol.

virtual bool isCalledFromScript ( )
inlineoverridevirtual

Get the flag that represents whether the call comes from the script or not,only use for the js.

false.

Reimplemented from ScriptEngineProtocol.

var isCalledFromScript ( )
inlineoverridevirtual

Get the flag that represents whether the call comes from the script or not,only use for the js.

false.

Reimplemented from ScriptEngineProtocol.

local isCalledFromScript ( )
inlineoverridevirtual

Get the flag that represents whether the call comes from the script or not,only use for the js.

false.

Reimplemented from ScriptEngineProtocol.

bool executeFunctionWithObjectData ( void *  nativeObj,
const char *  name,
JSObject *  obj 
)

Execute a js function with a JavaScript object as parameter.

By passing a native object, ScriptingCore will found its JavaScript object with the proxy. Then the function will be invoked with the native object's js proxy as caller. The caller object's C++ proxy. The function name. The JavaScript object as parameter. Return the js function's boolean result if successfully invoked, otherwise return false.

var executeFunctionWithObjectData ( var  nativeObj,
var  name,
var  obj 
)

Execute a js function with a JavaScript object as parameter.

By passing a native object, ScriptingCore will found its JavaScript object with the proxy. Then the function will be invoked with the native object's js proxy as caller. The caller object's C++ proxy. The function name. The JavaScript object as parameter. Return the js function's boolean result if successfully invoked, otherwise return false.

local executeFunctionWithObjectData ( local  nativeObj,
local  name,
local  obj 
)

Execute a js function with a JavaScript object as parameter.

By passing a native object, ScriptingCore will found its JavaScript object with the proxy. Then the function will be invoked with the native object's js proxy as caller. The caller object's C++ proxy. The function name. The JavaScript object as parameter. Return the js function's boolean result if successfully invoked, otherwise return false.

bool executeFunctionWithOwner ( jsval  owner,
const char *  name,
uint32_t  argc,
jsval *  vp 
)

Execute a js function with a JavaScript caller, function name, arguments count and arguments.

The caller object. The function name. The arguments count. The arguments. Return true if successfully invoked, otherwise return false.

var executeFunctionWithOwner ( var  owner,
var  name,
var  argc,
var  vp 
)

Execute a js function with a JavaScript caller, function name, arguments count and arguments.

The caller object. The function name. The arguments count. The arguments. Return true if successfully invoked, otherwise return false.

local executeFunctionWithOwner ( local  owner,
local  name,
local  argc,
local  vp 
)

Execute a js function with a JavaScript caller, function name, arguments count and arguments.

The caller object. The function name. The arguments count. The arguments. Return true if successfully invoked, otherwise return false.

bool executeFunctionWithOwner ( jsval  owner,
const char *  name,
uint32_t  argc,
jsval *  vp,
JS::MutableHandleValue  retVal 
)

Execute a js function with a JavaScript caller, function name, arguments count, arguments and a return value.

The caller object. The function name. The arguments count. The arguments. The js object to save the return value. Return true if successfully invoked, otherwise return false.

var executeFunctionWithOwner ( var  owner,
var  name,
var  argc,
var  vp,
var  retVal 
)

Execute a js function with a JavaScript caller, function name, arguments count, arguments and a return value.

The caller object. The function name. The arguments count. The arguments. The js object to save the return value. Return true if successfully invoked, otherwise return false.

local executeFunctionWithOwner ( local  owner,
local  name,
local  argc,
local  vp,
local  retVal 
)

Execute a js function with a JavaScript caller, function name, arguments count, arguments and a return value.

The caller object. The function name. The arguments count. The arguments. The js object to save the return value. Return true if successfully invoked, otherwise return false.

bool executeFunctionWithOwner ( jsval  owner,
const char *  name,
const JS::HandleValueArray &  args 
)

Execute a js function with a JavaScript caller, function name, arguments array.

This is more reliable in js memory management The caller object. The function name. The arguments array. Return true if successfully invoked, otherwise return false.

var executeFunctionWithOwner ( var  owner,
var  name,
var  args 
)

Execute a js function with a JavaScript caller, function name, arguments array.

This is more reliable in js memory management The caller object. The function name. The arguments array. Return true if successfully invoked, otherwise return false.

local executeFunctionWithOwner ( local  owner,
local  name,
local  args 
)

Execute a js function with a JavaScript caller, function name, arguments array.

This is more reliable in js memory management The caller object. The function name. The arguments array. Return true if successfully invoked, otherwise return false.

bool executeFunctionWithOwner ( jsval  owner,
const char *  name,
const JS::HandleValueArray &  args,
JS::MutableHandleValue  retVal 
)

Execute a js function with a JavaScript caller, function name, arguments array and a return value.

This is more reliable in js memory management The caller object. The function name. The arguments array. The js object to save the return value. Return true if successfully invoked, otherwise return false.

var executeFunctionWithOwner ( var  owner,
var  name,
var  args,
var  retVal 
)

Execute a js function with a JavaScript caller, function name, arguments array and a return value.

This is more reliable in js memory management The caller object. The function name. The arguments array. The js object to save the return value. Return true if successfully invoked, otherwise return false.

local executeFunctionWithOwner ( local  owner,
local  name,
local  args,
local  retVal 
)

Execute a js function with a JavaScript caller, function name, arguments array and a return value.

This is more reliable in js memory management The caller object. The function name. The arguments array. The js object to save the return value. Return true if successfully invoked, otherwise return false.

void executeJSFunctionWithThisObj ( JS::HandleValue  thisObj,
JS::HandleValue  callback 
)

Execute a js function with a js this object and the js function object.

The js this object. The js function object. Return true if successfully invoked, otherwise return false.

var executeJSFunctionWithThisObj ( var  thisObj,
var  callback 
)

Execute a js function with a js this object and the js function object.

The js this object. The js function object. Return true if successfully invoked, otherwise return false.

local executeJSFunctionWithThisObj ( local  thisObj,
local  callback 
)

Execute a js function with a js this object and the js function object.

The js this object. The js function object. Return true if successfully invoked, otherwise return false.

void executeJSFunctionWithThisObj ( JS::HandleValue  thisObj,
JS::HandleValue  callback,
const JS::HandleValueArray &  vp,
JS::MutableHandleValue  retVal 
)

Execute a js function with a js this object, the js function object, arguments and a return value.

The js this object. The js function object. The arguments array. The js object to save the return value. Return true if successfully invoked, otherwise return false.

var executeJSFunctionWithThisObj ( var  thisObj,
var  callback,
var  vp,
var  retVal 
)

Execute a js function with a js this object, the js function object, arguments and a return value.

The js this object. The js function object. The arguments array. The js object to save the return value. Return true if successfully invoked, otherwise return false.

local executeJSFunctionWithThisObj ( local  thisObj,
local  callback,
local  vp,
local  retVal 
)

Execute a js function with a js this object, the js function object, arguments and a return value.

The js this object. The js function object. The arguments array. The js object to save the return value. Return true if successfully invoked, otherwise return false.

bool evalString ( const char *  string,
JS::MutableHandleValue  outVal,
const char *  filename,
JSContext *  cx,
JS::HandleObject  global 
)

Evaluate the specified js code string The string with the javascript code to be evaluated The jsval that will hold the return value of the evaluation.

The filename The js context The js global object Return true if successfully invoked, otherwise return false.

var evalString ( var  string,
var  outVal,
var  filename,
var  cx,
var  global 
)

Evaluate the specified js code string The string with the javascript code to be evaluated The jsval that will hold the return value of the evaluation.

The filename The js context The js global object Return true if successfully invoked, otherwise return false.

local evalString ( local  string,
local  outVal,
local  filename,
local  cx,
local  global 
)

Evaluate the specified js code string The string with the javascript code to be evaluated The jsval that will hold the return value of the evaluation.

The filename The js context The js global object Return true if successfully invoked, otherwise return false.

bool evalString ( const char *  string,
JS::MutableHandleValue  outVal 
)

Evaluate the specified js code string.

Parameters
stringThe string with the javascript code to be evaluated
outValThe jsval that will hold the return value of the evaluation.
Returns
Return true if successfully invoked, otherwise return false.
var evalString ( var  string,
var  outVal 
)

Evaluate the specified js code string.

Parameters
stringThe string with the javascript code to be evaluated
outValThe jsval that will hold the return value of the evaluation.
Returns
Return true if successfully invoked, otherwise return false.
local evalString ( local  string,
local  outVal 
)

Evaluate the specified js code string.

Parameters
stringThe string with the javascript code to be evaluated
outValThe jsval that will hold the return value of the evaluation.
Returns
Return true if successfully invoked, otherwise return false.
bool evalString ( const char *  string)

Evaluate the specified js code string.

Parameters
stringThe string with the javascript code to be evaluated
Returns
Return true if successfully invoked, otherwise return false.
var evalString ( var  string)

Evaluate the specified js code string.

Parameters
stringThe string with the javascript code to be evaluated
Returns
Return true if successfully invoked, otherwise return false.
local evalString ( local  string)

Evaluate the specified js code string.

Parameters
stringThe string with the javascript code to be evaluated
Returns
Return true if successfully invoked, otherwise return false.
bool requireScript ( const char *  path,
JS::MutableHandleValue  jsvalRet 
)

Require the specified js file The difference between run and require is that require returns the export object of the script.

Parameters
pathThe path of the script to be executed
jsvalRetOn success, return the value from the last executed expression statement processed in the script
Returns
Return true if succeed, otherwise return false.
See also
https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_ExecuteScript
var requireScript ( var  path,
var  jsvalRet 
)

Require the specified js file The difference between run and require is that require returns the export object of the script.

Parameters
pathThe path of the script to be executed
jsvalRetOn success, return the value from the last executed expression statement processed in the script
Returns
Return true if succeed, otherwise return false.
See also
https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_ExecuteScript
local requireScript ( local  path,
local  jsvalRet 
)

Require the specified js file The difference between run and require is that require returns the export object of the script.

Parameters
pathThe path of the script to be executed
jsvalRetOn success, return the value from the last executed expression statement processed in the script
Returns
Return true if succeed, otherwise return false.
See also
https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_ExecuteScript
bool requireScript ( const char *  path,
JS::HandleObject  global,
JSContext *  cx,
JS::MutableHandleValue  jsvalRet 
)

Require the specified js file The difference between run and require is that require returns the export object of the script.

Parameters
pathThe path of the script to be executed
globalThe global object to execute the script
globalThe context to execute the script
jsvalRetOn success, return the value from the last executed expression statement processed in the script
Returns
Return true if succeed, otherwise return false.
See also
https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_ExecuteScript
var requireScript ( var  path,
var  global,
var  cx,
var  jsvalRet 
)

Require the specified js file The difference between run and require is that require returns the export object of the script.

Parameters
pathThe path of the script to be executed
globalThe global object to execute the script
globalThe context to execute the script
jsvalRetOn success, return the value from the last executed expression statement processed in the script
Returns
Return true if succeed, otherwise return false.
See also
https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_ExecuteScript
local requireScript ( local  path,
local  global,
local  cx,
local  jsvalRet 
)

Require the specified js file The difference between run and require is that require returns the export object of the script.

Parameters
pathThe path of the script to be executed
globalThe global object to execute the script
globalThe context to execute the script
jsvalRetOn success, return the value from the last executed expression statement processed in the script
Returns
Return true if succeed, otherwise return false.
See also
https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_ExecuteScript
void addRegisterCallback ( sc_register_sth  callback)

Add the register_sth callback to the list of functions that need to be called after the creation of the context.

It's normally used to register script bindings in the js context for bound classes The callback to register something to the js context

var addRegisterCallback ( var  callback)

Add the register_sth callback to the list of functions that need to be called after the creation of the context.

It's normally used to register script bindings in the js context for bound classes The callback to register something to the js context

local addRegisterCallback ( local  callback)

Add the register_sth callback to the list of functions that need to be called after the creation of the context.

It's normally used to register script bindings in the js context for bound classes The callback to register something to the js context

void createGlobalContext ( )

Create a new context.

If one is already there, it will destroy the old context and create a new one.

var createGlobalContext ( )

Create a new context.

If one is already there, it will destroy the old context and create a new one.

local createGlobalContext ( )

Create a new context.

If one is already there, it will destroy the old context and create a new one.

static void removeAllRoots ( JSContext *  cx)
static

Removes all rooted object in the given js context, rooted object won't be garbage collected.

The js context

var removeAllRoots ( var  cx)
static

Removes all rooted object in the given js context, rooted object won't be garbage collected.

The js context

local removeAllRoots ( local  cx)
static

Removes all rooted object in the given js context, rooted object won't be garbage collected.

The js context

int executeCustomTouchEvent ( cocos2d::EventTouch::EventCode  eventType,
cocos2d::Touch pTouch,
JSObject *  obj,
JS::MutableHandleValue  retval 
)

Simulate a touch event and dispatch it to a js object.

The touch event type The touch object The js object The return value of the touch event callback Return 1 if succeed, otherwise return 0.

var executeCustomTouchEvent ( var  eventType,
var  pTouch,
var  obj,
var  retval 
)

Simulate a touch event and dispatch it to a js object.

The touch event type The touch object The js object The return value of the touch event callback Return 1 if succeed, otherwise return 0.

local executeCustomTouchEvent ( local  eventType,
local  pTouch,
local  obj,
local  retval 
)

Simulate a touch event and dispatch it to a js object.

The touch event type The touch object The js object The return value of the touch event callback Return 1 if succeed, otherwise return 0.

int executeCustomTouchEvent ( cocos2d::EventTouch::EventCode  eventType,
cocos2d::Touch pTouch,
JSObject *  obj 
)

Simulate a touch event and dispatch it to a js object.

The touch event type The touch object The js object Return 1 if succeed, otherwise return 0.

var executeCustomTouchEvent ( var  eventType,
var  pTouch,
var  obj 
)

Simulate a touch event and dispatch it to a js object.

The touch event type The touch object The js object Return 1 if succeed, otherwise return 0.

local executeCustomTouchEvent ( local  eventType,
local  pTouch,
local  obj 
)

Simulate a touch event and dispatch it to a js object.

The touch event type The touch object The js object Return 1 if succeed, otherwise return 0.

int executeCustomTouchesEvent ( cocos2d::EventTouch::EventCode  eventType,
const std::vector< cocos2d::Touch * > &  touches,
JSObject *  obj 
)

Simulate a multi touch event and dispatch it to a js object.

The touch event type Touchs list for multitouch The js object Return 1 if succeed, otherwise return 0.

var executeCustomTouchesEvent ( var  eventType,
var  touches,
var  obj 
)

Simulate a multi touch event and dispatch it to a js object.

The touch event type Touchs list for multitouch The js object Return 1 if succeed, otherwise return 0.

local executeCustomTouchesEvent ( local  eventType,
local  touches,
local  obj 
)

Simulate a multi touch event and dispatch it to a js object.

The touch event type Touchs list for multitouch The js object Return 1 if succeed, otherwise return 0.

JSContext* getGlobalContext ( )
inline

Gets the current global context.

the global context

var getGlobalContext ( )
inline

Gets the current global context.

the global context

local getGlobalContext ( )
inline

Gets the current global context.

the global context

static bool log ( JSContext *  cx,
uint32_t  argc,
jsval *  vp 
)
static

Log something to the js context using CCLog.

The js context The arguments count The arguments Return true if succeed, otherwise return false.

var log ( var  cx,
var  argc,
var  vp 
)
static

Log something to the js context using CCLog.

The js context The arguments count The arguments Return true if succeed, otherwise return false.

local log ( local  cx,
local  argc,
local  vp 
)
static

Log something to the js context using CCLog.

The js context The arguments count The arguments Return true if succeed, otherwise return false.

bool setReservedSpot ( uint32_t  i,
JSObject *  obj,
jsval  value 
)

Sets a js value to the targeted js obejct's reserved slot, which is not exposed to script environment.

The slot index The targeted object The js value to set to the slot Return true if succeed, otherwise return false.

var setReservedSpot ( var  i,
var  obj,
var  value 
)

Sets a js value to the targeted js obejct's reserved slot, which is not exposed to script environment.

The slot index The targeted object The js value to set to the slot Return true if succeed, otherwise return false.

local setReservedSpot ( local  i,
local  obj,
local  value 
)

Sets a js value to the targeted js obejct's reserved slot, which is not exposed to script environment.

The slot index The targeted object The js value to set to the slot Return true if succeed, otherwise return false.

void debugProcessInput ( const std::string &  str)

Log a string to the debug environment.

Enable the debug environment so that it can be invoked. The message to log

var debugProcessInput ( var  str)

Log a string to the debug environment.

Enable the debug environment so that it can be invoked. The message to log

local debugProcessInput ( local  str)

Log a string to the debug environment.

Enable the debug environment so that it can be invoked. The message to log

void enableDebugger ( unsigned int  port = 5086)

Enable the debug environment, mozilla Firefox's remote debugger or Code IDE can connect to it.

The port to connect with the debug enviroment, default value is 5086

var enableDebugger ( var  port = 5086)

Enable the debug environment, mozilla Firefox's remote debugger or Code IDE can connect to it.

The port to connect with the debug enviroment, default value is 5086

local enableDebugger ( local  port = 5086)

Enable the debug environment, mozilla Firefox's remote debugger or Code IDE can connect to it.

The port to connect with the debug enviroment, default value is 5086

virtual void rootObject ( cocos2d::Ref ref)
overridevirtual

Roots the associated JSObj.

The GC won't collected rooted objects. This function is only called when compiled with CC_ENABLE_GC_FOR_NATIVE_OBJECTS=1

Reimplemented from ScriptEngineProtocol.

var rootObject ( var  ref)
overridevirtual

Roots the associated JSObj.

The GC won't collected rooted objects. This function is only called when compiled with CC_ENABLE_GC_FOR_NATIVE_OBJECTS=1

Reimplemented from ScriptEngineProtocol.

local rootObject ( local  ref)
overridevirtual

Roots the associated JSObj.

The GC won't collected rooted objects. This function is only called when compiled with CC_ENABLE_GC_FOR_NATIVE_OBJECTS=1

Reimplemented from ScriptEngineProtocol.

virtual void unrootObject ( cocos2d::Ref ref)
overridevirtual

Unroots the associated JSObj.

The GC will collect this object the next time the GC is called. This function is only called when compiled with CC_ENABLE_GC_FOR_NATIVE_OBJECTS=1

Reimplemented from ScriptEngineProtocol.

var unrootObject ( var  ref)
overridevirtual

Unroots the associated JSObj.

The GC will collect this object the next time the GC is called. This function is only called when compiled with CC_ENABLE_GC_FOR_NATIVE_OBJECTS=1

Reimplemented from ScriptEngineProtocol.

local unrootObject ( local  ref)
overridevirtual

Unroots the associated JSObj.

The GC will collect this object the next time the GC is called. This function is only called when compiled with CC_ENABLE_GC_FOR_NATIVE_OBJECTS=1

Reimplemented from ScriptEngineProtocol.

void jsb_ref_autoreleased_init ( JSContext *  cx,
JS::Heap< JSObject * > *  obj,
cocos2d::Ref ref,
const char *  debug 
)

Generic initialization function for subclasses of Ref.

Similar to jsb_ref_init(), but call it if you know that Ref has been autoreleased This function should never be called. It is only added as way to fix an issue with the static auto-bindings with the "create" function

var jsb_ref_autoreleased_init ( var  cx,
var  obj,
var  ref,
var  debug 
)

Generic initialization function for subclasses of Ref.

Similar to jsb_ref_init(), but call it if you know that Ref has been autoreleased This function should never be called. It is only added as way to fix an issue with the static auto-bindings with the "create" function

local jsb_ref_autoreleased_init ( local  cx,
local  obj,
local  ref,
local  debug 
)

Generic initialization function for subclasses of Ref.

Similar to jsb_ref_init(), but call it if you know that Ref has been autoreleased This function should never be called. It is only added as way to fix an issue with the static auto-bindings with the "create" function

void jsb_ref_rebind ( JSContext *  cx,
JS::HandleObject  jsobj,
js_proxy_t *  js2native_proxy,
cocos2d::Ref oldRef,
cocos2d::Ref newRef,
const char *  debug 
)

Disassociates oldRef from jsobj, and associates a new Ref.

Useful for the EaseActions and others

var jsb_ref_rebind ( var  cx,
var  jsobj,
var  js2native_proxy,
var  oldRef,
var  newRef,
var  debug 
)

Disassociates oldRef from jsobj, and associates a new Ref.

Useful for the EaseActions and others

local jsb_ref_rebind ( local  cx,
local  jsobj,
local  js2native_proxy,
local  oldRef,
local  newRef,
local  debug 
)

Disassociates oldRef from jsobj, and associates a new Ref.

Useful for the EaseActions and others

JSObject*
jsb_ref_autoreleased_create_jsobject
( JSContext *  cx,
cocos2d::Ref ref,
js_type_class_t *  typeClass,
const char *  debug 
)

Creates a new JSObject of a certain type (typeClass) and creates a proxy associated with and the Ref Similar to jsb_ref_create_jsobject(), but call it if you know that Ref has been autoreleased This function should never be called.

It is only added as way to fix an issue with the static auto-bindings with the "create" function

var
jsb_ref_autoreleased_create_jsobject
( var  cx,
var  ref,
var  typeClass,
var  debug 
)

Creates a new JSObject of a certain type (typeClass) and creates a proxy associated with and the Ref Similar to jsb_ref_create_jsobject(), but call it if you know that Ref has been autoreleased This function should never be called.

It is only added as way to fix an issue with the static auto-bindings with the "create" function

local
jsb_ref_autoreleased_create_jsobject
( local  cx,
local  ref,
local  typeClass,
local  debug 
)

Creates a new JSObject of a certain type (typeClass) and creates a proxy associated with and the Ref Similar to jsb_ref_create_jsobject(), but call it if you know that Ref has been autoreleased This function should never be called.

It is only added as way to fix an issue with the static auto-bindings with the "create" function

JSObject*
jsb_ref_get_or_create_jsobject
( JSContext *  cx,
cocos2d::Ref ref,
js_type_class_t *  typeClass,
const char *  debug 
)

It will try to get the associated JSObjct for ref.

If it can't find it, it will create a new one associating it to Ref. Call this function for objects that were already created and initialized, when returning getChild()

var jsb_ref_get_or_create_jsobject ( var  cx,
var  ref,
var  typeClass,
var  debug 
)

It will try to get the associated JSObjct for ref.

If it can't find it, it will create a new one associating it to Ref. Call this function for objects that were already created and initialized, when returning getChild()

local
jsb_ref_get_or_create_jsobject
( local  cx,
local  ref,
local  typeClass,
local  debug 
)

It will try to get the associated JSObjct for ref.

If it can't find it, it will create a new one associating it to Ref. Call this function for objects that were already created and initialized, when returning getChild()

JSObject*
jsb_ref_autoreleased_get_or_create_jsobject
( JSContext *  cx,
cocos2d::Ref ref,
js_type_class_t *  typeClass,
const char *  debug 
)

It will try to get the associated JSObjct for ref.

If it can't find it, it will create a new one associating it to Ref Call this function for objects that might return an already existing copy when you create them. For example, Animation3D::create();

var
jsb_ref_autoreleased_get_or_create_jsobject
( var  cx,
var  ref,
var  typeClass,
var  debug 
)

It will try to get the associated JSObjct for ref.

If it can't find it, it will create a new one associating it to Ref Call this function for objects that might return an already existing copy when you create them. For example, Animation3D::create();

local
jsb_ref_autoreleased_get_or_create_jsobject
( local  cx,
local  ref,
local  typeClass,
local  debug 
)

It will try to get the associated JSObjct for ref.

If it can't find it, it will create a new one associating it to Ref Call this function for objects that might return an already existing copy when you create them. For example, Animation3D::create();