void GLNode::onDraw(Mat4 &transform, uint32_t flags) { JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); js_type_class_t *typeClass = js_get_type_from_native<cocos2d::GLNode>(this); JS::RootedObject jsObj(cx, jsb_ref_get_or_create_jsobject(cx, this, typeClass, "cocos2d::GLNode")); if (jsObj.get()) { bool found = false; JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET JS_HasProperty(cx, jsObj, "draw", &found); if (found) { auto director = Director::getInstance(); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); JS::RootedValue rval(cx); JS::RootedValue fval(cx); JS_GetProperty(cx, jsObj, "draw", &fval); JS_CallFunctionValue(cx, jsObj, fval, JS::HandleValueArray::empty(), &rval); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); } } }
JSObject* js_get_or_create_jsobject(JSContext *cx, typename std::enable_if<std::is_base_of<cocos2d::Ref,T>::value,T>::type *native_obj) { js_type_class_t* typeClass = js_get_type_from_native<T>(native_obj); return jsb_ref_get_or_create_jsobject(cx, native_obj, typeClass, typeid(*native_obj).name()); }