Use VC to compile the Lua source code and generate the Lua interpreter and compiler.

Source: Internet
Author: User
Use VC to compile the Lua source code and generate the Lua interpreter and compiler.

1. Go to the web site to download the source code http://www.lua.org/download.html 2. Install a VC ++, I use vc6.0 3. Next we start to compile the source code, we need to compile:

  • A static library
  • One dynamic library
  • A Lua interpreter
  • A Lua Compiler
Create a static library project
  • Open VC --> file --> (click) create -- (select in the pop-up box) project --> (Win32 static library)
  • Create an empty project
  • Project name: lualib
  • Add all the source code in Lua and remove the Lua. C and luac. c files.
  • Compile and generate a static library ending with lualib. Lib (used later)
Create a dynamic job Library Project
  • Open VC --> file --> (click) create -- (select in the pop-up box) project --> (Win32 dynamic-Link Library)
  • Create an empty project
  • Project name: luadll
  • Add all the source code in Lua and remove the Lua. C and luac. c files.
  • Compile and generate a static library ending with luadll. dll (used later)
Create a console Project (generate Interpreter)
  • Open VC --> file --> (click) create -- (select in the pop-up box) project --> (Win32 console application)
  • Create an empty project
  • Project name: luainterpreter
  • Add only Lua. c
  • Click project ---> Settings --- link --> category --- (click drop-down box) --- enter --- category/module library to add the above static library name lualib. Lib
  • In order to find the added static library (lualib. Lib) during compilation, put it in your project directory, that is, the same folder as *. DSP. In this way, the compiler will find this library here.
  • Compile this sample to generate a luainterpreter.exe file. This executable file can run your Lua script.
  • Then, put the generated luadll.dllfile and luainterpreter.exe file in the same directory.
  • Open a window to access the directory where your luainterpreter.exe file is located.
  • Enter luainterpreter.exe test. Lua in the command line.
  • You can execute the test. Lua script.
Now write the following code in a text editor and save it as test. Lua.
function fact(n)if n == 0 then    return 1else    return n * fact(n - 1)endendprint("Enter a number:")a = io.read("*number")print(fact(a))
Create a console Project (generate compiler)
  • Open VC --> file --> (click) create -- (select in the pop-up box) project --> (Win32 console application)
  • Create an empty project
  • Project name: luacompile
  • Add only luac. c
  • Click project ---> Settings --- link --> category --- (click drop-down box) --- enter --- category/module library to add the above static library name lualib. Lib
  • In order to find the added static library (lualib. Lib) during compilation, put it in your project directory, that is, the same folder as *. DSP. In this way, the compiler will find this library here.
  • Compile this sample to generate a luacompile.exe file. This compiled file can compile your Lua script.

Link: http://www.cnblogs.com/activity-life/p/3583536.html

In addition, the differences between dynamic library and static library can be referred to: http://www.cnblogs.com/skynet/p/3372855.html

Use VC to compile the Lua source code and generate the Lua interpreter and compiler.

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.