1
2
3
4
5
6
|
extern
JSClass *jsb_cocos2d_Sprite_class;
JSObject *jsb_cocos2d_Sprite_prototype;
JSBool js_cocos2dx_Sprite_constructor(JSContext *cx,uint32_t argc,jsval *vp);
void
js_cocos2dx_Sprite_finalize(JSContext *cx,JSObject *obj);
js_register_cocos2dx_Sprite(JSContext *cx,JSObject *global);
register_all_cocos2dx(JSContext* cx,JSObject* obj);
|
jsb_cocos2d_Sprite_prototype = JS_InitClass(
cx,global,
jsb_cocos2d_Node_prototype,
jsb_cocos2d_Sprite_class,
dummy_constructor<cocos2d::Sprite>,
// no constructor
properties,
funcs,
NULL,0)!important; background:none!important">// no static properties
st_funcs);
<
class
T>
static
JSBool dummy_constructor(JSContext *cx,jsval *vp) {
JS::RootedValue initializing(cx);
JSBool isNewValid = JS_TRUE;
JSObject* global = ScriptingCore::getInstance()->getGlobalObject();
isNewValid = JS_GetProperty(cx,
"initializing"
,&initializing) && JSVAL_TO_BOOLEAN(initializing);
if
(isNewValid)
{
TypeTest<T> t;
js_type_class_t *typeClass = nullptr;
std::string typeName = t.s_name();
auto
typeMapIter = _js_global_type_map.find(typeName);
CCASSERT(typeMapIter != _js_global_type_map.end(),monospace!important; font-size:1em!important; min-height:inherit!important; color:blue!important; background:none!important">"Can't find the class type!"
);
typeClass = typeMapIter->second;
CCASSERT(typeClass,monospace!important; font-size:1em!important; min-height:inherit!important; color:blue!important; background:none!important">"The value is null."
);
JSObject *_tmp = JS_NewObject(cx,typeClass->jsclass,typeClass->proto,typeClass->parentProto);
JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(_tmp));
return
JS_TRUE;
}
JS_ReportError(cx,monospace!important; font-size:1em!important; min-height:inherit!important; color:blue!important; background:none!important">"Don't use `new cc.XXX`,please use `cc.XXX.create` instead! "
);
JS_FALSE;
}
DERIVED >
TypeTest
{
public
:
static
const
char
* s_name()
{
// return id unique for DERIVED
// ALWAYS VALID BUT STRING,NOT INT - BUT VALID AND CROSS-PLATFORM/CROSS-VERSION COMPATBLE
// AS FAR AS YOU KEEP THE CLASS NAME
return
typeid
( DERIVED ).name();
}
};