"Quick-cocos2d-x 3.3 How to bind your own definition class to LUA IV" use a self-defined class that binds C + + to Lua

Source: Internet
Author: User
Tags lua python script

Continued "Quick-cocos2d-x 3.3 How to bind oneself define class to Lua three" bind yourself to define the class to Lua. We're finished. Define the class-to-lua binding. In the next step, we will use it.

First, we need to determine which binding files we generated through the Python script. Let's list a form.


//Path:f:\cocos2dx-lua\garfield\frameworks\cocos2d-x\cocos\scripting\lua-bindings\auto

1. Lua_pet_auto.hpp

//Path: F:\Cocos2dx-Lua\Garfield\frameworks\cocos2d-x\cocos\scripting\lua-bindings\auto

2. Lua_pet_auto.cpp

// Path: F:\Cocos2dx-Lua\Garfield\frameworks\cocos2d-x\cocos\scripting\lua-bindings\auto\api

3. Lua_pet_auto_api.lua

//Path: F:\Cocos2dx-Lua\Garfield\frameworks\cocos2d-x\cocos\scripting\lua-bindings\auto\ API

4. Pet.lua


Check whether these files are in the relative path of your project.

(F:\Cocos2dx-Lua\Garfield This is the path to my Demo sample project ).

All right, we'll use VS2013 to open the "Garfield.sln" project file. We will introduce "lua_pet_auto.hpp", "lua_pet_auto.cpp"in "Libluacocos2d\auto".

These two files declare and define a "Register_all_custom_pet ()" global function. Used to complete the registration of the C + + binding class. The "injection" of the member properties and member functions to LUA in the class is implemented to "parse" the C + + class structure into LUA.

" Register_all_custom_pet () "Function we'll use in a minute .





Check that the "Pet" class file we created in the third chapter has been properly introduced into vs2013project.


& nbsp   After the introduction of these files, we will call . font-size:18px; line-height:30px "> " Register_all_custom_pet () " function to complete the registration of the binding class in the project.

< Span style= "font-family: ' Microsoft Yahei '; font-size:18px; line-height:30px ">   1. Introduce   #include "lua_pet_auto.hpp"   header files;   (  "Register_all_custom_pet ()   "defined in the file )

2. Call "Register_all_custom_pet ()".


watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvbwfycg9vbhm=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">


Next, we are able to use the "Pet" in the Quick-cocos2d-x project. I will write my script in the Cocos Code IDE, which uses the class pet defined by C + +. For example, the following:


Go back to Vs2013project and execute the project.

Suppose you come across such as " open VSProject Import lua_pet_auto.cpp and LUA_PET_AUTO.HPP, lua_pet_auto.cpp Error said the pet.h file compilation error said .. \auto\lua_pet_auto.cpp (2): Fatal error C1083: Cannot open include file: "Pet.h": No such file or directory" This error, please refer to the following, The include path for class is filled in vs.





In the end, in order to hope to help to see the blog post of the reader, I try to each of the links have been specific and explained, will inevitably slightly repeat. at the same time carefully verify each link. But there are inevitably flaws. Suppose you find a problem in the process of reading. can email [email protected] contact me, very happy to communicate with you.


"Quick-cocos2d-x 3.3 How to bind your own definition class to LUA IV" use a self-defined class that binds C + + to Lua

Related Article

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.