lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Oct 17, 2011, at 11:27 PM, Victor Young wrote:

I've considered this method before. It's useful, but when the table has many keys, it will be troublesome and easy to make mistakes. Thanks any way!

You could construct things as:

local t = magic_table()
-- t records the sequence in which keys are first assigned

t.x = 1
t.y = 2
t.a = 3
t.b = 4

for k, v in t:iter() do
print( k, v )
end

The __pairs metamethod in 5.2 (I think) will avoid the problem with stealing the key iter in the above example.

Mark