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