How to list the variables inside a table in Lua?

3

For example:

minion = {
   hp = 1000,
   x = 10,
   y = 25
}

Is there any function that I can know how many variables exist within this table?

    
asked by anonymous 08.08.2015 / 13:15

1 answer

4

There is already a answer for size . To scroll through the elements:

minion = {
    hp = 1000,
    x = 10,
    y = 25 }

for i, v in pairs(minion) do
    print(i, "=>", v)
end

See running on ideone .

    
08.08.2015 / 13:39