Lua Tutorial
Lua is a lightweight, compact scripting language written in standard C and open as source code. Its design purpose is to be embedded in applications, thereby providing flexible extension and customization capabilities for applications.
Lua was developed in 1993 by a research group at the Pontifical Catholic University of Rio de Janeiro in Brazil. The group members were: Roberto Ierusalimschy, Waldemar Celes, and Luiz Henrique de Figueiredo.
Design Purpose
Its design purpose is to be embedded in applications, thereby providing flexible extension and customization capabilities for applications.
Lua Features
- Lightweight: It is written in standard C and open as source code. After compilation, it is only a little over 100K, and can be easily embedded into other programs.
- Extensible: Lua provides very easy-to-use extension interfaces and mechanisms: the host language (usually C or C++) provides these functions, and Lua can use them as if they were built-in features.
-
Other Features:
- Supports procedure-oriented programming and functional programming;
- Automatic memory management; only provides a general-purpose type of table, which can be used to implement arrays, hash tables, sets, and objects;
- Built-in pattern matching; closures; functions can also be viewed as a value; provides support for multithreading (coroutines, not threads supported by the operating system);
- Through closures and tables, it can conveniently support some key mechanisms needed in object-oriented programming, such as data abstraction, virtual functions, inheritance, and overloading.
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
The file extension of Lua code files is.lua。
Next, we use Lua to output "Hello World!"
Example (Lua 5.3)
print("Hello World!")
Run Example »
After running, it will display Hello, world! on the screen.
Other Extensions