Cocos2dx lua calls the C ++ class.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.