Lua Tutorial


Lua is a lightweight and compact scripting language, written in standard C language and open in source code form. It is designed to be embedded in applications to provide applications with Flexible expansion and customization capabilities.

Lua is a research team at the Pontifical Catholic University of Rio de Janeiro in Brazil, composed of Roberto Ierusalimschy, Waldemar Celes and Luiz Henrique de Figueiredo and developed in 1993.

Design purpose

It is designed to be embedded in applications to provide flexible expansion and customization functions for applications.

Lua features

  • Lightweight: It is written in standard C language and is open in source code form. After compilation, it only takes one More than a hundred K can be easily embedded into 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 They are like built-in functions.

  • Other features:

    • Supports procedure-oriented programming and functional programming ( functional programming);

    • Automatic memory management; only provides a general type of table (table), which can be used to implement arrays, hash tables, collections, and objects;

    • Language built-in pattern matching; closure; function can also be regarded as a value; provides multi-threading (co-process, not threads supported by the operating system) support;

    • Closures and tables can easily support some key mechanisms required for object-oriented programming, such as data abstraction, virtual functions, inheritance and overloading, etc.

Lua application scenario

  • Game development

  • Independent application script

  • Web application script

  • Extensions and database plug-ins such as: MySQL Proxy and MySQL WorkBench

  • Security systems, such as intrusion detection systems

The first Lua program

Next we use Lua to output "Hello World!"


print("Hello World!")

Run instance»

Click the "Run instance" button to view the online instance

After running , Hello, world! will be displayed on the screen.