table

A table is a basic Lua type, it implements associative arrays.

An associative array is an array that can be indexed not only with numbers, but also with strings or any other value of the language, except nil.

local t = {} -- create an empty table

t["x"] = 10 -- set value == 10 for "x" key
t.x = 10 -- does the exact same thing

-- ⚠️ --
t[x] = 10 -- this sets a value for the "value of x" key

A table may store values with different types of indices and it grows as it needs to accommodate new entries:

local t = {} 
t.foo = "bar"
t[2] = 10
t["test"] = true

A table can be initialized with values:

local days = {"Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday"}
-- days[1] == "Sunday"
-- days[2] == "Monday"
-- ...

local position = {x=1, y=2}
-- position.x == 1
-- position.y == 2