Cocos2d-x-3.0beta2 custom lua calls c ++ class

Source: Internet
Author: User

As mentioned above, how to use the interface of the method bindingcocos2d-x provided by 3.0beta2, let's take a look at the following if binding custom class

There is a folder named bindings-generator under the cocos2d-x root directory, which has a test, which can be seen in test. sh, test. ini, userconf. ini. sample also provides the custom c ++ Code provided by simple_test.

First, rename the userconf. ini. simple file as userconf. ini, open the userconf. ini file, and set the parameters

[DEFAULT]
Androidndkdir =$ {path to your ndk}/android-ndk-r9b
Clangllvmdir =$ {androidndkdir}/toolchains/llvm-3.3/prebuilt/darwin-x86_64
Cxxgeneratordir =$ {Your cocos2d-x path}/tools/bindings-generator/test /..
Extra_flags =

Next, open test. sh. Note that the ndk mentioned earlier must use r9b. Pay attention to the last line of this file.

LD_LIBRARY_PATH =$ {users}/libclang $ PYTHON_BIN $ {CXX_GENERATOR_ROOT}/generator. py $ {users}/test. ini-t spidermonkey-s testandroid-o $ {OUT_PATH}

Spidermonkey is mentioned here. This is a js engine, so we need to banding lua. Therefore, we need to modify the parameters in this line to replace spidermonkey with lua.

LD_LIBRARY_PATH =$ {users}/libclang $ PYTHON_BIN $ {CXX_GENERATOR_ROOT}/generator. py $ {CXX_GENERATOR_ROOT}/test. ini-t lua-s testandroid-o $ {OUT_PATH}

What does this line mean?

The first two are the paths of the tools (for example, tools) to be used.

The third is the INI file path corresponding to your custom class (if you need to bind your own class later, you need to modify this INI file. We recommend that you do not write it by yourself, take this test. you can modify the content in the template by using ini)

The fourth step is to specify the name in the INI file. This should be consistent with the name of the first line [] in the INI file.

The fifth is the output path.

After completing these configurations, you can use test. sh is used to bind the c ++ class in this example. If nothing is modified by default, the js interface is bound. Here we modify the output to be the lua interface.

Run the same terminal cd to the test folder and run./test. sh. If there is no error, it will be output to the out_path path, three files, hpp, cpp, and js.

Binding has been completed.

Test. ini content needs to be modified, first of all to understand the meaning of each parameter, In the cocos2d-x/tools/tolua/cocos2d ini file, there are detailed notes, comparison test. ini should be able to achieve the goal easily.

The key is to find out how to call the c ++ class if binding custom lua


The above is self-developed. I don't know if the official team really wants to tell us the practice. If there is a better and more convenient way, please leave a message and give us some advice. I am very grateful.

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.