Tables

Tables in Lua can be dictionaries or arrays.

Arrays are special dictionaries where the index is automatically assigned and the first value is at index 1. The “#” operator also works for arrays, but it will not result in the correct value for tables such as dictionaries in general.

An inspect function is available as part of Lua in Feko that allows you to easily view the contents of a table.

an_array = {1,1,2,3,5,8,13}
print(#an_array) -- prints "7"
print(an_array[3]) -- prints "2"
a_table = {[ ' bread ' ] = "brown", [ ' eggs ' ] = 10} -- tables are dictionaries or arrays
print(a_table[ ' bread ' ]) -- "prints brown"
print(a_table) -- prints "table: 0x7f63c8001200", the memory location of the table
inspect(a_table) -- prints the contents of the table
print(#a_table) -- prints "0" since it is not an array (take note)