Continued "Quick-cocos2d-x 3.3 How to bind a custom class to Lua three" after binding a custom class to Lua, we have completed the custom 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 that these files are relative to the path in your project. (F:\Cocos2dx-Lua\Garfield This is the path where my sample project is located ).
All right, we use VS2013 to open the "Garfield.sln" project file. We will introduce it in "Libluacocos2d\auto""lua_pet_auto.hpp" , "lua_pet_auto.cpp " . These two files declare and define the Register_all_custom_pet () global function to complete the registration of the C + + binding class, complete the member properties in the class and "inject" the member function 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 the VS2013 project.
After the introduction of these files, we will call "Register_all_custom_pet ()" in the engine Ingress protocol class "Appdelegate" 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 ()".
Next, we can 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 + +. As follows:
Go back to the VS2013 project and run the project.
In the end, in order to hope that we can help to see the blog post of the reader, I try to each link has been detailed and explained, will inevitably be a little verbose . at the same time carefully verify each link, but inevitably there are flaws, if you in the process of reading to find problems. can email [email protected] contact me, very happy to communicate with you.
"Quick-cocos2d-x 3.3 How to bind a custom class to Lua IV" using a custom class that binds C + + to Lua