如何从c ++ cocos2d-x

时间:2018-09-08 06:25:05

标签: javascript c++ cocos2d-x cocos2d-js

我有一个如下的javascript文件:

var helloWorld = function(age, name) {
    // do something
    cc.log("age=%d, name=%s", age, name);
};

var MyObject = cc.Class.extend({
    ctor: function() {},
    testFunc: function(str) {
        cc.log("testFunc: str=%s", str);
    }
});
var myObject = new MyObject();

现在,如何在c ++中调用helloWorld函数和myObject.testFunc

#include "cocos2d.h"
#include "scripting/js-bindings/manual/js_bindings_core.h"
#include "scripting/js-bindings/manual/cocos2d_specifics.hpp"

class MyCppObject {
public:
    MyCppObject() {}

    void callJavascript() {
        int age = 20;
        std::string name = "cocos2dx";
        std::string str = "xxx";
        // TODO: how can I call `helloWorld` function and `myObject.testFunc` in c++ with arguments
    }
}

0 个答案:

没有答案
相关问题