COCOS JSBinding Workflow
Setup JSB Enviroment
ScriptingCore* sc = ScriptingCore::getInstance();
sc->addRegisterCallback(register_all_cocos2dx);
sc->addRegisterCallback(register_cocos2dx_js_core);
sc->addRegisterCallback(jsb_register_system);
// ......
sc->start();
sc->runScript("jsb_boot.js");initRegister
initRegisterScriptingCore::ScriptingCore() {
initRegister();
}
void ScriptingCore::initRegister() {
this->addRegisterCallback(registerDefaultClasses);
}addRegisterCallback
addRegisterCallbackcreateGlobalContext
createGlobalContextjsb_prepare.js
jsb_prepare.jsRegister registrationList
registrationListRegister registerDefaultClasses
registerDefaultClassesRegister cc namespace
cc namespaceRegister global Functions
FunctionsRegister register_all_cocos2dx
register_all_cocos2dxRegister js_register_cocos2dx_Node
js_register_cocos2dx_NodeAdd to _js_global_type_map
_js_global_type_mapRegister Other Native Classes
Classesjsb_boot.js
jsb_boot.jsCreate Cocos Object
Call new cc.Sprite("xxx.png") from javascript
new cc.Sprite("xxx.png") from javascriptTrigger ctor in C++
ctor in C++Create NativeObject cocos::Sprite
NativeObject cocos::SpriteCreate JSObject
JSObjectBind NativeObject with JSObject
NativeObject with JSObjectAdd JSObject to GC Root
JSObject to GC RootReturn created Object to javascript
Object to javascriptCall _ctor in javascript if any from C++
_ctor in javascript if any from C++jsb_create_apis.js
Trigger initWithFile in C++
initWithFile in C++Try to find the NativeObject (cobj) bind with the JSObject
NativeObject (cobj) bind with the JSObjectCall initWithFile on NativeObject with param
initWithFile on NativeObject with paramRemove Cocos Object
Call removeFromParentAndCleanup from javascript
removeFromParentAndCleanup from javascriptTrigger removeFromParentAndCleanup in C++
removeFromParentAndCleanup in C++Try to find the NativeObject bind to the JSObject when created
NativeObject bind to the JSObject when createdCall removeFromParent on NativeObject with param
removeFromParent on NativeObject with paramC++ do the remove stuffs
C++ do the remove stuffsTrigger cocos::Ref destructor
cocos::Ref destructorTrigger removeScriptObjectByObject in C++
removeScriptObjectByObject in C++Find the JSObject bind to the NativeObject
JSObject bind to the NativeObjectRemove the JSObject from GC Root
JSObject from GC RootRemove the proxy
proxyEvent Register in Cocos
Call addCustomListener from javascript
addCustomListener from javascriptTrigger addCustomEventListener in C++
addCustomEventListener in C++Check Function
FunctionCreate JSFunctionWrapper with this and onGameShow
JSFunctionWrapper with this and onGameShowCreate a lambda for Callback with data
lambda for Callback with dataCreate cocos2d::EventListenerCustom
cocos2d::EventListenerCustomReturn cocos2d::EventListenerCustom to javascript
cocos2d::EventListenerCustom to javascriptEvent Dispatch in Cocos
Call dispatchCustomEvent from javascript
dispatchCustomEvent from javascriptCreate cc.EventCustom in javascript
cc.EventCustom in javascriptTrigger EventCustom_constructor in C++
EventCustom_constructor in C++Set user data in javascript
javascriptCall dispatchEvent
dispatchEventTrigger EventDispatcher_dispatchEvent in C++
EventDispatcher_dispatchEvent in C++Trigger stored lamba function
lamba functionJSAPI invoke called
JSAPI invoke calledjavascript receive event with data
javascript receive event with dataGet user data stored in javascript
javascriptCallFunc in Cocos
Call cc.callFunc in javascript
cc.callFunc in javascriptTrigger CallFunc_ctor in C++
CallFunc_ctor in C++Trigger _ctor in javascript
_ctor in javascriptTrigger initWithFunction in C++
initWithFunction in C++Create JSCallbackWrapper to keep the param
JSCallbackWrapper to keep the paramAdd a lamba function to NativeObject
lamba function to NativeObjectTrigger lamba from C++
lamba from C++Trigger callback in javascript
callback in javascriptSchedule in Cocos
Call schedule in javascript
schedule in javascriptTrigger node_schedule in C++
node_schedule in C++Get the Schedule Object bind to the NativeObject
Schedule Object bind to the NativeObjectCreate a JSScheduleWrapper to keep params
JSScheduleWrapper to keep paramsCall schedual function on the NativeObject
schedual function on the NativeObjectTrigger JSScheduleWrapper::scheduleFunc
Trigger callback in javascript
callback in javascriptLast updated