[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: A question about table's length
- From: Vaughan McAlley <ockegheim@...>
- Date: Sat, 2 Jan 2010 13:42:43 +1100
2010/1/2 Leo Razoumov <slonik.az@gmail.com>:
> It is not for the purpose of preserving the length of the result but
> rather to preserve the iteration order. Using "pair" on Lua table does
> not guarantee the order of iteration. "ipair" while guaranteeing the
> order of iteration will choke on the first "nil" value. Replacing
> "nil" with "false" allows to iterate with "ipair" over all the results
> from "map" and skip the "false" values using "if" conditionals.
>
> --Leo--
>
Hmmm... ipairs is easy to replace:
a = {}
a[1] = 1
a[2] = nil
a[3] = 3
for i = 1, table.maxn(a) do
print(i, a[i])
end
Is the issue that this is not strictly an iterator?
Vaughan