Links
- See also: MoonScript, a language that compiles to Lua
- Libraries
- Live web-based interpreter
- pdf: Programming with Multiple Paradigms in Lua
- Faq
- Unofficial FAQ
- Gotchas
- A nice set of docs
- Beware: Only use the links that start with "Lua".
- Lua Tricks (introductory material)
- Loops and Control Structures
- Named arguments (like keyword parameters)
- Lua Functional Programming
- Inspired by and based on Paul Graham's work On Lisp
- Introduction
- Functions
- Online book: Programming in Lua
- This is an online version of the first edition of the book
- Part II · Tables and Objects
- Part III · The Standard Libraries
- Wiki are not easy to find from there.
- Manual - Table of Contents
- LUA 5.2
- Memoization
Types
There are eight basic types in Lua: nil, boolean, number,
string, function, userdata, thread, and table
. Nil
is the
type of the value nil
The type thread
represents independent threads of execution
and it is used to implement coroutines (see §2.11). Do not
confuse Lua threads with operating-system threads. Lua
supports coroutines on all systems, even those that do not
support threads.
The type table
implements associative arrays, that is,
arrays that can be indexed not only with numbers, but with
any value (except nil
). Tables can be heterogeneous; that
is, they can contain values of all types (except nil
).
Tables are the sole data structuring mechanism in Lua; they
can be used to represent ordinary arrays, symbol tables,
sets, records, graphs, trees, etc. To represent records, Lua
uses the field name as an index. The language supports this
representation by providing a.name
as syntactic sugar for
a["name"]. There are several convenient ways to create
tables in Lua (see §2.5.7).
Like indices, the value of a table field can be of any type
(except nil
). In particular, because functions are
first-class values, table fields can contain functions. Thus
tables can also carry methods
(see §2.5.9).
Tables, functions, threads, and (full) userdata values are objects: variables do not actually contain these values, only references to them. Assignment, parameter passing, and function returns always manipulate references to such values; these operations do not imply any kind of copy.
The library function type
returns a string describing the
type of a given value.