Associative table order

Hmm. Not sure if I’ve misunderstood something in how Lua tables work, or if this is a bug in the Corona daily build, but in trying to debug something I’ve put together the following test:

local test = {} test["G"] = 1 test["W"] = 2 test["V"] = 3 test["R"] = 4 for k,v in pairs(test) do print(k .. " - " .. v) end

I expected that the iteration would either return the pairs in the order they were created in, or alphabetically by key. Instead the result is as follows:

R - 4 G - 1 W - 2 V - 3

Is this expected behaviour? If so, what order are tables iterated when using pairs() and is there any way to force iteration by order created?

Never mind - discovered this is just normal Lua behaviour and that maintaining a separate numeric table for ordering is the accepted approach.

Sometimes Lua still baffles me!

Never mind - discovered this is just normal Lua behaviour and that maintaining a separate numeric table for ordering is the accepted approach.

Sometimes Lua still baffles me!