1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
//在AppDelegate::applicationDidFinishLaunching函数中
ScriptingCore* sc = ScriptingCore::getInstance();
sc->addRegisterCallback(register_all_cocos2dx);
sc->addRegisterCallback(register_all_cocos2dx_extension);
sc->addRegisterCallback(register_cocos2dx_js_extensions);
sc->addRegisterCallback(register_all_cocos2dx_extension_manual);
sc->addRegisterCallback(jsb_register_chipmunk);
sc->addRegisterCallback(JSB_register_opengl);
sc->addRegisterCallback(jsb_register_system);
sc->addRegisterCallback(MinXmlHttpRequest::_js_register);
sc->addRegisterCallback(register_jsb_websocket);
sc->addRegisterCallback(register_all_cocos2dx_builder);
sc->addRegisterCallback(register_CCBuilderReader);
sc->addRegisterCallback(register_all_cocos2dx_gui);
sc->addRegisterCallback(register_all_cocos2dx_gui_manual);
sc->addRegisterCallback(register_all_cocos2dx_studio);
sc->addRegisterCallback(register_all_cocos2dx_studio_manual);
sc->addRegisterCallback(register_all_cocos2dx_spine);
|
2
var
node = cc.Node.create();
node.setVisible(
false
);
auto
node = CCNode::create();
node->setVisible(
false
当然,SpiderMonkey远远还不止干了这些,还做了很多事,比如绑定和查找JS和C++对象的对应关系,包装参数为对应类型,类型安全检查,返回值包装等等。要知道他干了些什么,直接看引擎代码是更好的选择。
19
JSBool js_cocos2dx_Node_create(JSContext *cx,uint32_t argc,jsval *vp)
{
if
(argc == 0) {
cocos2d::Node* ret = cocos2d::Node::create();
jsval jsret = JSVAL_NULL;
do
{
(ret) {
js_proxy_t *proxy = js_get_or_create_proxy<cocos2d::Node>(cx,(cocos2d::Node*)ret);
jsret = OBJECT_TO_JSVAL(proxy->obj);
}
else
{
jsret = JSVAL_NULL;
}
while
(0);
JS_SET_RVAL(cx,vp,jsret);
return
JS_TRUE;
}
JS_ReportError(cx,
"js_cocos2dx_Node_create : wrong number of arguments"
);
JS_FALSE;
}
1
jsval jsret = JSVAL_NULL;