Compiling and using Lua script in Windows C + + 1

Source: Internet
Author: User
Tags lua

The earlier use of Lua, just a small part of the project, suddenly arose to write some articles about Lua, to record the points that have been learned.

I'm using LUA5.2 as a case here.

Lua as a lightweight scripting language has been widely used in applications and game development, compared to Perl and Python Lua kernel only about 100KB

Can be easily embedded into the language level just as the language itself functions

The following from Baidu General branch:

LUA also has other features: support for process-oriented (procedure-oriented) programming and functional programming (functional programming), automatic memory management, and only a common type of table, which enables arrays, Hash table, set, object, language built-in pattern matching, closure (closure), function can also be regarded as a value, multi-threading (collaborative process [4], not supported by the operating system) support; Through closures and tables it is easy to support some of the key mechanisms required for object-oriented programming, such as data abstraction, virtual functions, inheritance and overloading, and so on.

What is closures? And how to use closures in the following article there is a closure problem for JavaScript. I believe many front-end engineers are not strangers

Closures are always semi-existent because of their pros and cons, so many people don't recommend using closures in their programs.

http://www.cnblogs.com/jeffwongishandsome/archive/2009/05/17/1458405.html Introduction to Closures

Needless to say, to use LUA first to compile the LUA kernel, Linux is quite simple

Make

Make install is finished

The process of compiling Windows is as follows

What if you want to compile a static library?

VS2010 first create the following items, remember to remove the precompiled header, because Lua is C, mixed C + + will cause a precompiled header conflict

Create a static library that does not apply to precompiled headers.


Import the LUA code into the project file and choose your LUA code import directly to generate it


What if you are compiling a dynamic library?

The basic steps are the same as you create a DLL project at the time of creation, or directly modify the project properties to build the DLL


Are you compiling now? You want to get rid of your precompilation options!!! Do not use the project precompiled header


This time you compile OK through the also generated DLL, then the problem came now I did not build. LIB Storage!!!

Actually found that the LUA kernel export function is declared as LUA_API beginning

You need to add a few precompiled definitions

Lua_build_as_dll this tells the preprocessor code to compile according to the DLL and define the import export

Lua_core this tells the preprocessor LUA_API macro to add dllexport export definition if not added is to use DllImport directly

The source code is as follows

1 #ifDefined (Lua_build_as_dll)/* {*/2 3 #ifDefined (Lua_core) | | Defined (lua_lib)/* {*/4 #defineLua_api __declspec (dllexport)5 #else/* }{ */6 #defineLua_api __declspec (dllimport)7 #endif/* } */8 9 #else/* }{ */Ten  One #defineLUA_API extern A  - #endif/* } */

OK here your LUA kernel is compiled and you can start learning Lua.


Compiling and using Lua script in Windows C + + 1

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.