February 4, 2011

Simple arrays in Lua language

Arrays in Lua are based on Lua's tables.

Declaration of an array:

sample_array = {}

Addition of a new element into the sample_array:

table.insert( sample_array, some_var )

How to get array size:

array_size = #sample_array

Access to the array elements ( the first element has index 1 ):

for i=1, #sample_array do
   message( sample_array[i] )
end -- for

Lua 5.1 Reference Manual

No comments:

Post a Comment