Lua is a small, fast, dynamically typed language designed to be embedded in other programs. Its whole implementation is tiny and it talks to C easily, so games, editors, network devices and embedded systems use it for configuration and scripting. It has few features, and builds everything from one data structure, the table.
Key concepts
- Tables: the only data structure, used as array, dictionary, object and module.
- First-class functions and closures: functions are values and capture their variables.
- Metatables: tables whose behaviour, such as indexing and operators, is customised, which builds objects and inheritance.
- Coroutines: cooperative tasks that yield and resume, useful for generators and state machines.
- Embedding: a host program creates a Lua state, exposes functions and runs scripts through a stack-based C interface.
- Small standard library: deliberately little, so hosts provide the rest.
Vocabulary
- Chunk: a piece of Lua code loaded and run as a function.
- Metamethod: a function in a metatable that overrides an operation.
- Host: the program that embeds the Lua interpreter.
- Nil: the single absent value, and the only false besides false itself.
What to study, in order
- Basic syntax, tables, loops and functions, using the standalone interpreter.
- Closures, varargs, string handling and error handling with pcall.
- Metatables: build a class system and operator overloading.
- Coroutines: write a generator and a simple scheduler.
- Embed Lua in a small C program and expose one function to scripts.
- Read the language's reference manual, which is short and complete.