The installation and Lua Lua Lua variables -TTLSA (a)

Business is useful to Lua, combining high-performance web applications with nginx, want to understand this knowledge, understanding learning went under Lua, welcomed the large cracking enlighten. Introduction 1. Lua Lua is a simple programming language, it has the advantage that it can integrate C ++ modules to extend its functionality, the use of several hundred lines or less code to solve complex problems. Have features are: 1.1 Scalability:. Lua from the outset was designed to be easily extensible language, many features are achieved through external library easily with other programming languages ​​such as C, C ++, Java, and so were interaction. 1.2 succinct: Lua is very simple, but powerful, easy to learn, it is suitable for small-scale applications. 1.3 Efficient:. Lua has a high efficiency. 1.4 Portability: Lua can run on any existing system. Lua script is a simple script that contains a series of commands Lua extension of a text file named .lua. A single command or a series of commands of a script file, in Lua, we call it a code block. Block: a control means within the structure, a function thereof, or a the chunk (file or text string variable that is declared). 2. Lua Lua environment to build up first installation, ease of learning behind the demonstration.
# curl -R -O http://www.lua.org/ftp/lua-5.2.3.tar.gz
# tar zxvf lua-5.2.3.tar.gz 
# cd lua-5.2.3/src
# make linux
2.2 常见问题解决方法 问题1: lua.c:67:31: error: readline/readline.h: No such file or directory lua.c:68:30: error: readline/history.h: No such file or directory 解决方法: # yum install readline-devel 问题2: make all SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lreadline" make[1]: Entering directory `/root/lua-5.2.3/src' gcc -o lua lua.o liblua.a -lm -Wl,-E -ldl -lreadline /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libreadline.so: undefined reference to `PC' /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libreadline.so: undefined reference to `tgetflag' /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libreadline.so: undefined reference to `tgetent' /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libreadline.so: undefined reference to `UP' /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libreadline.so: undefined reference to `tputs' /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../. ./lib64/libreadline.so: undefined reference to `tgoto '/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libreadline.so: undefined reference to `tgetnum '/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libreadline.so: undefined reference to` BC' / usr / lib /gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libreadline.so: undefined reference to `tgetstr 'solution: Since there is no link ncurses library, you need to add - lncurses can be./usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libreadline.so: undefined reference to `BC '/ usr / lib / gcc / x86_64- redhat-linux / 4.1.2 /../../../../ lib64 / libreadline.so: undefined reference to `tgetstr 'solution: Since there is no link ncurses library, you need to add -lncurses./usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libreadline.so: undefined reference to `BC '/ usr / lib / gcc / x86_64- redhat-linux / 4.1.2 /../../../../ lib64 / libreadline.so: undefined reference to `tgetstr 'solution: Since there is no link ncurses library, you need to add -lncurses.
# vim ./src/Makefile
linux:
 $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lreadline -lncurses"
And therefore we can introduce variables that need anywhere 3. Lua Lua variable, the variable declaration is not required can be used. Tracking of variables becomes difficult. This requires us to use them, be extra careful so as not to different functions with a variable of the same name caused confusion data. At the same time, you do not need to specify the type of a variable, such as nul, boolean, string, number, table. Depending on the type of the variable to the value of its prose. An un-initialized variable access also can not go wrong, but the results obtained are null nil. Type function may be used to determine the type of the variable. Such as:
# ./lua
> value = 'www.ttlsa.com'
> print (type(value))
string
> value = 39514058
> -- ttlsa.com 运维生存时间Q群
> print (type(value))
number
3.1 Lua global variables are global variables default, remains unchanged during the entire session, unless you change it. When using global variables, plus a variable before the letter g will be more clear. However, try to use local variables. 3.2 local variables local to create a local variable, global variables, local variables are only valid within that block is declared. Define local variables can be set to an initial value it may not be. The> local value1> local vlaue2 = 'www.ttlsa.com' 4. Lua single line comment Syntax Notes: - Multi-line comments: - [[-]] 5. Lua command line
usage: ./lua [options] [script [args]]
Available options are:
  -e stat  execute string 'stat'  //直接将命令传入Lua
  -i       enter interactive mode after executing 'script'  //进入交互模式
  -l name  require library 'name'  //加载一个文件
  -v       show version information  //打印版本信息
  -E       ignore environment variables //忽略环境变量
  --       stop handling options
  -        stop handling options and execute stdin
# ./lua -e "print(type('www.ttlsa.com'))"
string
Lua global variable arg stored command-line parameters. In the run before, Lua use all parameters arg constructor table. Script name index is 0, 1 from the script parameter begins to increase. Preceding script parameter starts to decrease from -1.
> lua -e "sin=math.sin" script a b
arg表如下:
arg[-3] = "lua"
arg[-2] = "-e"
arg[-1] = "sin=math.sin"
arg[0] = "script"
arg[1] = "a"
arg[2] = "b"

Reproduced in: https: //my.oschina.net/766/blog/210947

Guess you like

Origin blog.csdn.net/weixin_33860528/article/details/91493247