Cocos2dx lua calls the C ++ class.
We need a series of tedious preparations. tolua ++: This is a required tool. tolua ++ prepares a test class. copy the code // MyClass. hclass MyClass {public: MyClass () {}; int foo (int I) ;}; // MyClass. pkg $ # include "MyClass. h "class MyClass {MyClass (); int foo (int I) ;}; copy the code. Note that I didn't give it. cpp, because you do not need to care about this at this time. note. pkg format. It is a class description. It has its own set of rules. For details, go to other places ~ To generate a file, use tolua ++ to generate the file. command Line: tolua-n packname-o D: \ luaMyClass. cpp D: \ MyClass. pkg packname: package name, followed by the output path and input path. in. in cpp, there is a tolua _ [package name] _ open () function. this function is the key to import. in AppDelegate. cpp, add the following code. auto plua = engine-> getLuaStack ()-> getLuaState (); tolua_test_open (plua); then we can use it freely in lua.