LANGUAGE ยป LUA

Table

Basic โ€‹

Table is a mix of list and hashmap.

lua
mylist = {'a', 'b', 'c'}
mylist_length = #mylist
is_empty = next(mylist) == nil

Functions โ€‹

FunctionDescription
insertInsert an element at the specified position (defaults to last).
removeRemove an element at the specified position (defaults to last).
concatFlattens the list into a string (like join in other languages).
sortSort a list with an optional function.
moveMove elements from a table to another.
packReturn a copy of the given table as list (indexed with numbers).
unpackReturn elements of list as different variables.

Examples โ€‹

Insert value into table:

lua
table.insert(mytable, "new element")

Use pairs() or ipairs() to loop it:

lua
for index, value in pairs(mylist) do
    print(index, value)
end