A quick overview of Lua

Subject : NGINX with LUA scripting language can achieve complex control. Here is a quick start on Lua.

About Lua : Lua is a scripting language, written in C language, open source, which is designed for embedded applications program provides a convenient extension for the application that provides flexible customization capabilities (using the embedded Lua scripts to achieve application configurable and extensible), Lua was born in 1993, by the Pontifical Catholic University of Rio de Janeiro (Pontifical Catholic University of Rio de Janeiro ) in the development of a research team, team members from Roberto Ierusalimschy, Waldemar Celes, and Luiz Henrique de Figueiredo.

lua language mainly used in the field of game programming, in addition, also used in stand-alone applications lua script, web application scripts, plug-ins and other extensions and databases, Lua there is a more significant features, it is relatively simple, such as the python C 54 million lines of source code, python-free C source code of the core module has 17 million lines, lua5.3 all C source code only 2.4 million lines , for all practical language is currently seen in the smallest size of the source.

Lua also has its memory management mechanism, Lua uses automatic memory management, developers do not care about how to create an object memory is allocated, we do not care about the question of release objects after not being used, those Lua will automatically go to treatment, so development people save heart to do more important things.

We all know that, like C ++, java, Objective-C, c #, php and other languages ​​support object-oriented programming, object-oriented programming is a very popular computer programming architecture, and similarly, we want to say today Lua language also supports object-oriented programming of.

Lua syntax : syntax language Lua and other similar, if you have experience with other computer languages, then look at the tutorial to learn Lua, Lua will also start soon, like other computer languages, lua variables, loops, data type, process control functions, these operators are currently reserved keywords lua 21.

Lua Notes : Compared with the comments of php, php is a single-line comment // or # (double slash is used more), while the lua single-line comment is - (Lua represented by two minus one-line comments, which Like a little annotation sql language).

php is based on multi-line comments "/ *" at the beginning, "* /" at the end, while the lua language, multi-line comment that end in "- - [[" beginning "]]" .

Lua installation: Lua can be installed on a Linux system, Mac systems and windows system, here with Linux, for example, briefly about the installation of Lua

Firstly to carry out commands are available for download from the fixed

curl -R -O “http://www.lua.org/ftp/lua-5.3.0.tar.gz”

Then decompress the downloaded file

takes zxf lua-5.3.0.tar.gz

Then enter the appropriate directory is to install, simple.

Contact cd-5.3.0

make linux test

make install

Write hello world with lua

The first example of a program php: echo "hello world!":

The first program of java: System.out.println ( "hello world!");

The first program of Lua: print ( "Hello World!")

This code will be written above the lua file named HelloWorld.lua, then at the command line to execute lua HelloWorld.lua, you can see the output Hello World! In the console you,

Well, this, on the first successful use Lua to write a simple program up!

Lua tutorial link

Published 60 original articles · won praise 73 · Views 230,000 +

Guess you like

Origin blog.csdn.net/tyyking/article/details/99989096