Lua tutorial


Release date:2023-09-26 Update date:2023-10-13 Editor:admin View counts:199

Label:

Lua tutorial

Lua

Lua is a lightweight and compact scripting language written in the standard C language and open in source code. It is designed to be embedded in the application so as to provide flexible extension and customization for the application.

Lua was developed in 1993 by a research team at the Catholic University (Pontifical Catholic University of Rio de Janeiro) in Rio de Janeiro, Brazil. The team members are Roberto Ierusalimschy, Waldemar Celes and Luiz Henrique de Figueiredo.

Design purpose

It is designed to be embedded in the application, so as to provide flexible extension and customization for the application.

Lua characteristics

  • Lightweight: it is written in standard C language and open in source code. After compilation, it is only more than 100 K, and can be easily embedded inother programs.

  • Extensibility: Lua provides very easy-to-use extension interfaces and mechanisms: these functions are provided by the host language (usually C or C++) and can be used by Lua as if they were built-in functionality.

  • Other features:

    • Support for process oriented (procedure-oriented) programming and functionalprogramming (functional programming);

    • Automatic memory management; only one common type of table (table) is provided, which can be used to implement arrays, hash tables, collections, and objects:

    • Language built-in pattern matching; closure; function can also be seen as a value; provides multithreading (collaborative processes, not threads supported by the operating system)

    • Closures and table can easily support some of the key mechanisms needed for object-oriented programming, such as data abstraction, virtual functions, inheritance and overloading.

Lua application scenario

  • Game development

  • Stand-alone 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 the Lua to output "Hello World!"

Instance (Lua 5.3)

print("Hello World!")

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

Powered by TorCMS (https://github.com/bukun/TorCMS).