Lua Getting Started tutorial

May 12, 2021 13:00 Lua

Table of contents

Lua Getting Started tutorial

Lua Getting Started tutorial

Lua is a lightweight, compact scripting language, written in standard C and open in source code, designed to be embedded in applications to provide flexible extensions and customization capabilities for applications.

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

Design purpose

It is designed to be embedded in applications, providing flexible extensions and customization capabilities for applications.

Lua feature

  • Lightweight: It is written in standard C language and open in source code form, compiled after only a hundred K, can be easily embedded in other programs.
  • Scalable: Lua provides very easy-to-use extension interfaces and mechanisms: these features are provided by the host language (usually C or C++), and Lua can use them as if they were built-in.
  • Other features :
    • Supports process-oriented programming and functional programming;
    • Automatic memory management, which provides only a common type of table, which enables arrays, hash tables, collections, objects;
    • Language built-in pattern matching; closure; functions can also be considered a value; and multithreaded (collaborative processes, not threads supported by the operating system) are supported;
    • Closures and tables make it easy to support some of the key mechanisms required for object-oriented programming, such as data abstraction, virtual functions, inheritance, and overloading.

Lua scenario

  • Game development
  • Apply the script independently
  • Web app scripts
  • 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!

Example (Lua 5.3)

print("Hello World!")

Try it out . . .

After running, Hello, world!