
Getting started - Lua
Lua is designed to be a lightweight embeddable scripting language. It is used for all sorts of applications , from games to web applications and image processing. See the about page for a detailed description of Lua and some reasons why you should choose Lua.
Programming in Lua : 1
If you are using the stand-alone Lua interpreter, all you have to do to run your first program is to call the interpreter (usually named lua) with the name of the text file that contains your program. For instance, if you write the above program in a file hello.lua, the following command should run it: prompt> lua hello.lua
Programming in Lua : 1.1
You may use the -i option to instruct Lua to start an interactive session after running the given chunks. A command line like prompt> lua -i -la -lb will run the chunk in a, then the one in b, and then prompt you for interaction. This is especially useful for debugging and manual testing.
Programming in Lua : 8.1
Lua offers a higher-level function to load and run libraries, called require. Roughly, require does the same job as dofile , but with two important differences. First, require searches for the file in a path; second, require controls whether a file has already been run to avoid duplicating the work.
4.3.1 – if then else - Lua
When you write nested ifs, you can use elseif. It is similar to an else followed by an if , but it avoids the need for multiple end s: if op == "+" then r = a + b elseif op == "-" then r = a - b elseif op == "*" then r = a*b elseif op == "/" then r = a/b else error("invalid operation") end
- [PDF]
Lua Performance Tips
Once you decide that you really must optimize your Lua code, t his text may help you about how to optimize it, mainly by showing what is sl ow and what is fast in Lua.
Programming in Lua : 1.4
The stand-alone interpreter (also called lua.c due to its source file, or simply lua due to its executable) is a small program that allows the direct use of Lua. This section presents its main options.
Programming in Lua : 2.4
Lua handles long strings quite efficiently. Programs that manipulate strings with 100K or 1M characters are not unusual in Lua. We can delimit literal strings by matching single or double quotes:
Lua 5.3 Reference Manual
The host program can invoke functions to execute a piece of Lua code, can write and read Lua variables, and can register C functions to be called by Lua code. Through the use of C functions, Lua can be augmented to cope with a wide range of different domains, thus creating customized programming languages sharing a syntactical framework.
Programming in Lua : 5.1
Lua always adjusts the number of results from a function to the circumstances of the call. When we call a function as a statement, Lua discards all of its results. When we use a call as an expression, Lua keeps only the first result.