/**
@brief Execute a scripted global function.
@brief The function should not take any parameters and should return an integer.
@param functionName String object holding the name of the function,in the global script environment,that is to be executed.
@return The integer value returned from the script function.
*/
virtual int executeGlobalFunction(const char* functionName) { 0; }
int sendEvent(cocos2d::ScriptEvent* message) override;
bool parseConfig(ConfigType type,const std::string& str) override;
bool handleAssert(char *msg) { false; }
void setCalledFromScript(bool callFromScript) { _callFromScript = callFromScript; };
bool isCalledFromScript() { return _callFromScript; };
bool executeFunctionWithObjectData(void* nativeObj,255); line-height:1.5!important">char *name,JSObject *obj);
bool executeFunctionWithOwner(jsval owner,uint32_t argc = NULL);
void executeJSFunctionWithThisObj(jsval thisObj,jsval callback,0); line-height:1.5!important">*
* will eval the specified string
* @param string The string with the javascript code to be evaluated
* @param outVal The jsval that will hold the return value of the evaluation.
* Can be NULL.
bool evalString(char *string,jsval *outVal,255); line-height:1.5!important">char *filename = NULL,jscontext* cx = NULL,JSObject* global = NULL);
修改jsb_kenko_auto.cpp:
#include ";
}
vp) {
cclOG(it's c++ testCallback here");
jscontext* jc = Scriptingcore::getInstance()->getGlobalContext();
// 注释部分适合有对象化的调用
参考:http://www.tairan.com/archives/4902
jsval v[2];
v[0] = int32_to_jsval(jc,32);
v[1] = int32_to_jsval(jc,12);
通过 Scriptingcore 封装好的方法实现回调,可以帮助我们节省很多细节上的研究
js_proxy_t * p = jsb_get_native_proxy();
return Scriptingcore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj),"cpp_callback",2,v); 2是参数个数,v是参数列表
找到一个更适合全局函数的方法
jsval ret;
return Scriptingcore::getInstance()->evalString(cpp_callback(2,3)ret);
}
0);
JS_DefineFunction(cx,0); line-height:1.5!important">test_cpp_callback0);
}