[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: table iteration problem
- From: Enrico Colombini <erix@...>
- Date: Tue, 18 Oct 2011 09:45:33 +0200
On 18/10/2011 8.09, steve donovan wrote:
To get the order you want, one way is to keep a sub-table of the keys
in order, and use that for iteration.
Or, assuming numbers here are arbitrary and not just consecutive, if you
need a table of pairs you could store them as subtables:
-- elements with no key are stored in order (table as array)
t = {
{'x', 1},
{'y', 2},
{'a', 3},
{'b', 4}
}
-- read them back in the same order (note 'ipairs')
for _, s in ipairs(t) do
print(s[1], s[2])
end
--> output:
x 1
y 2
a 3
b 4
--
Enrico