Lua Tutorial
Lua is a lightweight, small-sized scripting language written in standard C and open-sourced in its source code form. Its design purpose is to be embedded in applications to provide flexible extension and customization capabilities.
Lua was developed by a research group at Pontifical Catholic University of Rio de Janeiro, Brazil, in 1993. The group members included Roberto Ierusalimschy, Waldemar Celes, and Luiz Henrique de Figueiredo.
Design Purpose
Its design purpose is to be embedded in applications to provide flexible extension and customization capabilities.
Lua Features
Lightweight: It is written in standard C and open-sourced in its source code form, compiling to just over a hundred K, making it easy to embed in other programs.
Extensible: Lua provides very easy-to-use extension interfaces and mechanisms: these functions are provided by the host language (usually C or C++), and Lua can use them as if they were built-in features.
Other Features:
Supports procedural programming and functional programming;
Automatic memory management; provides only one generic type of table, which can be used to implement arrays, hash tables, sets, objects;
Built-in pattern matching; closures; functions can also be treated as values; provides support for multithreading (coroutines, not threads supported by the operating system);
Supports key mechanisms required for object-oriented programming, such as data abstraction, virtual functions, inheritance, and overloading, through closures and tables.
Lua Application Scenarios
Game development
Standalone application scripts
Web application scripts
Extensions and database plugins such as MySQL Proxy and MySQL WorkBench
Security systems, such as intrusion detection systems
First Lua Program
Next, we will use Lua to output "Hello World!"
Example (Lua 5.3)
print("Hello World!")
Upon running, "Hello, world!" will be displayed on the screen.