Version is lua5.1 vs 2013
Reprinted from http://blog.csdn.net/wangbin_jxust/article/details/37557807
First, open vs2010 second, create the project
Create a new project->win32 console application, and then select the static library in the application settings, and do not tick the precompiled header. Specific example:
Third, copy the source code
Copy the *.h file from the LUA source to the project's header file folder and copy the *.c file from the LUA source to the project's source file folder.
Iv. generation of Lua.lib
Project right-click Build. You can now see the generated lua.lib under the Debug folder of your project.
In the previous article, we talked about how to compile the LUA source code and generate Lua.lib (read using vs2010 to compile lua5.1 source lua.lib), and in the new project we continue to use the previous project to learn how to invoke Lua using C + +. If you encounter unprotected error in the call to Lua API errors, refer to the procedure at the end of this article.
There may be some security warning errors during build
To prohibit some security warnings (Windows programmers know why), you need to modify the configuration properties->c/c++–> preprocessor---preprocessor definition, add at the end
;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_DEPRECATE
First, create the project
Also in this solution, add Project, right-click Solution, named Testlua, select Win32 Console program, no additional configuration is required, select done.
Ii.. Configuration Items
Add a new reference to the LUA project by right-clicking the common properties, such as the framework and references, Testlua project.
Right-Testlua Project---Configuration Properties->c/c++-> general---Add the LUA source address in the included directory.
Third, code calls
[CPP]View PlainCopyprint?
- #include "stdafx.h"
- extern "C"
- {
- #include <lua.h>
- #include <lualib.h>
- #include <lauxlib.h>
- }
- int _tmain (int argc, _tchar* argv[])
- {
- Lua_state *l = Lua_open ();
- Lual_openlibs (L);
- const Char *buf = "Print (' Hello world ')";
- Lual_dostring (L,BUF);
- Lua_close (L);
- GetChar (); This sentence can make you clearly see the printed Hello World
- return 0;
- }
Create LUA files in the current CPP file in the same directory, create a Test.lua file, the file is written with LUA code, here I write the print ("Hello World from Lua file") Four, complete the direct operation, you can output "Hello World "and Hello World from Lua file. If you encounter an error in the unprotected error in the call to Lua API (unable to get Modulefilename), modify the character set for two items, the general character "Modified to use multibyte character set" with the Unicode character set.
Basic interaction between LUA and C + + 1