lua-users home
lua-l archive

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


On Oct 3, 2013, at 7:15 PM, Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> wrote:

>> Lua table distinguishes sequential keys (from 1 through N) that can be
>> iterated in order using ipairs from the other keys iterated via pairs
>> that visit all the keys in a non-specified order.
> 
> No, Lua makes no such distinction. ipairs does because it provides a view
> of the table as a sequence.

But it doesn't. ipairs() just iterates until it hits the first nil, regardless of any subsequent numeric keys. The Lua reference quite clearly defines a sequence such that additional numeric keys after a nil are not allowed (or, equivalently, that there are no "holes" in the sequence). ipairs() really has nothing to do with sequences so far as I can see.

I'm unaware of any efficient way to iterate backwards through a sequence in Lua.

--Tim