Lua table as list

Tables can be used as arrays, functioning much like a list. Try copy pasting this code into the translator:

local Primes = {1,2,5,7,11,13,17} trace(Primes); trace(#Primes); for i=1, #Primes do trace(i); end

Putting the # Operator on Lua Tables gives the number of elements in the array.

As you can see, it’s quite straightforward to use the number of elements in the array in afor loop to iterate through an table like this:

Next, see Lua tables as dictionaries.

 

 

Related pages