VS build lua development environment and LuaBridge register c ++ class (cocos2dx project) (1), luabridgecocos2dx

Source: Internet
Author: User

VS build lua development environment and LuaBridge register c ++ class (cocos2dx project) (1), luabridgecocos2dx

Because the project uses Lua development and has recently studied lua, we are preparing to build a lua development environment under. The project uses LuaBridge to bind a C ++ object to Lua. This article writes the usage of LuaBridge together and begins the text below...


1. Generate Lua static library (for non-cocos2dx projects, refer to this article http://www.fusijie.com/blog/2014/08/31/how-to-complie-cpp-with-lua-in-the-vs)

(1) first download Lua from the Lua website. The latest version is Lua 5.2.3. After downloading, decompress the package and put it aside for use... You can also go to the cocos2dx source code to obtain, the path is as follows E: \ cocos2d-x-3.1.1 \ external \ lua

(2) create a cocos2dx project, right-click solution to add a new project, select the win32 console program, OK, select the static library, check the pre-compilation header, and OK... For example:

(3) create a folder LuaSrc under the liaLua directory and copy the downloaded lua code... Enter the project to add to libLua, add _ CRT_SECURE_NO_WARNINGS under configuration properties-> c/c ++/Preprocessor definition, and set the output directory to be the same as other static libraries to generate, in LuaTest \ proj. win32 \ Debug. the win32 Directory has a libLua. lib static library file. Now, we have successfully generated the Lua static library.

2. Add LuaBridge to the project and register the object.

Ps: Because LuaBridge requires Lua, you need to add dependencies and include directories to the project, including libLua. lib and $ (EngineRoot) libLua.

(1) first download the LuaBridge source file. The LuaBridge file enters the project directory, adds the folder LuaBridge, and then adds the downloaded file to the folder. Enter the project, add the LuaBridge folder, add existing items, add files in LuaBridge to the project, and add # include "LuaBridge/LuaBridge. h "header file, test OK. register the c ++ object for lua..

(2) register two classes for testing using the AddEvent and Widget classes. First, you need to add several libraries to register widgets. The Code is as follows:


 1 void HelloLua::initScripts(lua_State* L) 2 { 3     getGlobalNamespace(L) 4  5         .beginNamespace("game") 6         .beginClass<Widget>("Widget") 7         .addFunction("getChildByName", &Widget::getChildByName) 8         .endClass() 9         .endNamespace()10 11 12         ;13 }

OK. Here is an introduction to environment setup and c ++ class registration. The next article starts to write two classes to complete button event registration.


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.