Type Table Library table.* Keywords table See also Introduction to Lua (guide)
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"]
.
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 the Introduction to Lua guide for more information.