vs2013 how to invoke Lua in C + + (ii)

Source: Internet
Author: User
Tags lua

Lua Learning notes vs2013 How to invoke Lua in C + + (this is a reprint tutorial) I tried it completely.

First, the preparatory work

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

2, the source is stacked on the appropriate disk (my in D, path D:/LUA-5.2.3/SRC)

3. Open vs2013 to create a new Win32 Console application (Win32 console project), I named him Lualib

4, after the confirmation, the Application wizard will pop up the prompt box, click Next. Application type select Static library, add option to remove precompiled header (precomplied header), click Done.

5. Add the header file (. h) to the project and the source code (. C)

1) Copy all the. h files in the D:/lua-5.2.3/src to the header files

2) Copy all. c files in the D:/LUA-5.2.3/SRC to the source file (Code files)

6. Configuration item properties, opening project---Properties--Configuration properties

1) in the C + + item midpoint Open the general, the first additional inclusion directory fill in D:/LUA-5.2.3/SRC

2) at the midpoint of C + + items, the second is compiled to select compile to C code (/TC)

7. Build the project, generate the Lua.lib file in the debug (Release) file after the build is successful. Here I generated the times wrong:

Error c4996: ' fopen ': This function or variable could be unsafe

If this error occurs, you will need to add the _crt_secure_no_warnings to the preprocessor definition in the property page to generate it again.

Second, call Lua in C + + code

1, the new Win32 Console application program, named Testlua, the back of the need not change

2. Add a lualib reference to the common properties of the project

3, in C + + items in the middle of the general, the first add-on included in the directory to fill in D:/LUA-5.2.3/SRC

4. Write code in TestLua.cpp

#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, in the Testlua directory into the pre-written Test.lua file

6. Set Testlua as the startup item and run the project

vs2013 how to invoke Lua in C + + (ii)

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.