lua-users home
lua-l archive

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


On 2 August 2010 03:28, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
>> >ipairs in work4 behaves identically to the 5.1 version. (with the
>> >exception of returning nil in place of nothing)
>> >
>> >Is the doc wrong or the code?
>> >
>> >
>>
>> I believe the doc is wrong, since the thinking was that since ipairs
>> is being deprecated there was no reason to also change its
>> functionality.
>
> The doc is wrong, but not because of this thinking (given that it is not
> being deprecated any more). The problem is that, with the possibility
> of tables to redefine '#', the implementation was wrong, and a correct
> implementation was somewhat expensive (checking against '#' in every
> iteration).
>
> Anyway, ipairs is back with its 5.1 semtantics.
>
> -- Roberto
>

I think the new semantics are appropriate; though I think you should
use the raw length...
for tables that redefine __len; they should also be defining __ipairs
(if relevant)

Daurn