VS2010 Ultimate + LUA environment configuration

First, the preparatory work

1, Lua source code download, address: http: //www.lua.org/download.html (I use the latest version 5.2.3)

2, the source code in the appropriate disk (in my D drive, the path D: /Lua-5.2.3/src)

3, open vs2010 create a win32 console application (Win32 console project), I will be his name is LuaLib

4, determined, will pop up a prompt box of the Application Wizard, click Next. Application Type select Static Library (static Library), an additional option to remove precompiled header (Precomplied Header), click Finish.

5, add the header file (.h) to the project and source code (.c)

1) The D: /lua-5.2.3/src all .h files are copied to the header file (Header Files) in

2) D: /lua-5.2.3/src .c files to copy all source files (Code Files) in

 

 

6, Configuration Item Properties, open the project -> Properties -> Configuration Properties

1) In the C / C ++ routine entry opening midpoint, the first directory containing additional fill D: /lua-5.2.3/src

2) In the C / C ++ entry opening midpoint advanced, to select the second compiled code is compiled into C (/ TC)

7, build the project, after the success will generate Debug (Release) file generated lua.lib file. Here I generated a mistake Times:

error c4996: 'fopen': This function or variable may be unsafe 

If this error occurs, you need to join in the pre-defined processor _CRT_SECURE_NO_WARNINGS property page, again generated on it.

 

 

Second, calling Lua code in C ++

1, the new win32 console application, named for the TestLua, do not change back 

2, add the library project in linker (LUA library named 12345.lib) and the folder where you





3, in C / C ++ routine entry opening midpoint, the first directory containing additional fill D: /lua-5.2.3/src

4, the code is written in TestLua.cpp

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <iostream>
extern "C" {
     #include <lua.h>
     #include <lualib.h>
     #include <lauxlib.h>
}
int _tmain( int argc, _TCHAR* argv[])
{  
     using namespace std;   
     lua_State *L = luaL_newstate();
     luaL_openlibs(L);  
     luaL_dofile(L, "test.lua" );
     lua_close(L);  
     cin.get(); 
     return 0;
}

5, into the prior written test.lua file in the directory TestLua

  test.lua so write: print ( "hello, world \ nThis is lua \ n!.")

6, set TestLua to start, and run the project

Published 12 original articles · won praise 6 · views 20000 +

Guess you like

Origin blog.csdn.net/huaweizte123/article/details/53911631