@151880692 写道:
JS:
onLoad: function () { this.label.string = this.text; cc.log("====111"); var customClass = cc.CustomClass.create(); customClass.callback = function(i, j){ //this.label.string = "callback"; cc.log("customClass.callback: " + i + j); }; var msg = customClass.helloMsg() //this.label.string = msg cc.log("customClass's msg is ===: " + msg) },
C++:
std::string CustomClass::helloMsg() { js_proxy_t * p = jsb_get_native_proxy(this); //jsval retval; JSContext* jc = ScriptingCore::getInstance()->getGlobalContext(); // 定义参数,由两个参数 jsval v[] = { v[0] = int32_to_jsval(jc, 32), v[1] =UINT_TO_JSVAL(88) }; // 通过 ScriptingCore 封装好的方法实现回调,可以帮助我们节省很多细节上的研究 ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), "callback", 2, v); CCLOG("===IN HELLO MSG"); return "Hello from CustomClass::sayHello"; }
帖子: 2
参与者: 1