Detailed description of Lua programming language installation environment

Source: Internet
Author: User

LuaProgramming LanguageInstallEnvironment is the content to be introduced in this article,LuaIt is an extended programming language designed to support generic procedural programming and provide relevant data descriptions.LuaIt also supports object-oriented programming,FunctionData-driven programming provides good support. It can be used as a powerful and lightweight scripting language for any program.LuaProvided in the form of a library written in clean C. The so-called Clean C Refers to a subset of ansi c and C ++)

As an Extended Language, Lua does not have the concept of a "main" program: it can only work in one host program, which is called the embedding program or host for short. The host program can execute a small segment by calling the function.LuaCode. You can read and write Lua variables and inject the C function to call Lua code. These extended C functions can greatly expand the field in which Lua can process transactions, so that various languages can be customized, and they share a unified syntax format framework.

LuaThe official release contains a simple host program called lua, which uses the Lua library to provide an independent Lua interpreter. Lua is a free software. Its license determines that its use process is generally not guaranteed.

Lua installation (in linux:

Method 1)

My operating system is:

 
 
  1. Linux oracle-desktop 2.6.31-14-generic #48-Ubuntu SMP Fri Oct 16 14:05:01 UTC 2009 x86_64 GNU/Linux 

Use the sudo apt-get install lua5.1 command to install lua directly. However, when embedding lua in the C language, lua cannot be found. h and other files. Therefore, if you simply run the lua command to execute some lua statements, this is enough, but if you embed it in the C language, you must use method 2.

Method 2)

My operating system is:

 
 
  1. Linux oracle-desktop 2.6.31-14-generic #48-Ubuntu SMP Fri Oct 16 14:05:01 UTC 2009 x86_64 GNU/Linux 

1) first go to Lua's official website http://www.lua.org/ftp/) download the latest release package, I chose lua-5.1.4.tar.gz

2) use the command tar-xzvf lua-5.1.4.tar.gz

3) cd lua-5.1.4, and then execute make, will prompt you enter make system, because my system is linux, So I enter make linux

 
 
  1. However, error: readline/readline. h: no such file or directory is reported during the running process,
  2. I searched zookeeper for readline-6.1.tar.gz installation, so I went to wget
  3. Http://www.sfr-fresh.com/unix/misc/readline-6.1.tar.gz
  4. Tar-zxvf readline-6.1.tar.gz, cd ~~ ./Configure & make install, sudo ldconfig,
  5. Run make linux again. The readline error is not reported, but the prompt is displayed.
  6. /Usr/bin/ld: cannot find-lncurses
  7. I searched the internet and had to download the ncurses installation, wget
  8. Http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.7.tar.gz,
  9. Tar-xvf ncurses -5.7.tar.gz, and then cd ncurses-5.7,./configure, make, make install,
  10. Run make linux again and everything will be OK.

4) sudo make install

InstallComplete.

Test whether lua is successfully installed. Run lua directly to enter the compilation mode.

Lua InstallationAfter that, you can use the example of embedding lua in c provided by the lua manual to put the following program into a. c:

 
 
  1. #include <stdio.h> 
  2. #include <lua.h> 
  3. #include <lauxlib.h> 
  4. #include <lualib.h> 
  5.  
  6. int main(int argc, char *argv[])  
  7. {  
  8.         char line[BUFSIZ];  
  9.         lua_State *L = lua_open();  
  10.         luaL_openlibs(L);  
  11.         while (fgets(line, sizeof(line), stdin) != 0) printf("%s/n",line);  
  12.  
  13.         lua_close(L);  
  14.         return 0;  

Run the following command:

 
 
  1. gcc -I/usr/local/include/ -L/usr/local/lib/ -lm -DLUA_USE_READLINE a.c /usr/local/lib/liblua.a -ldl 

Run the command to compile the program.

If you run gcc a. c directly, the following error is reported:

 
 
  1. /tmp/ccI4JYia.o: In function `main':  
  2. a.c:(.text+0x28): undefined reference to `luaL_newstate'  
  3. a.c:(.text+0x3e): undefined reference to `luaL_openlibs'  
  4. a.c:(.text+0x81): undefined reference to `lua_close'  
  5. collect2: ld returned 1 exit status 

This is becauseLuaThe c api in the standard library is called, so the database must be added.

Summary: DetailsLuaProgramming LanguageInstallThe environment has been introduced. I hope this article will help you!

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.