lua-users home
lua-l archive

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


Thank you, that explains it.


> Il giorno 27 feb 2023, alle ore 06:18, Joseph C. Sible <josephcsible@gmail.com> ha scritto:
> 
> https://www.lua.org/manual/5.1/manual.html#2.5.5 explains it: "If the
> array has "holes" (that is, nil values between other non-nil values),
> then #t can be any of the indices that directly precedes a nil value".
> It's not even guaranteed that the same implementation will always give
> the same result when there are holes.
> 
> Joseph C. Sible
> 
> On Mon, Feb 27, 2023 at 12:14 AM Gianmaria Bajo <mg1979.git@gmail.com> wrote:
>> 
>> I found some discrepancies between LuaJIT (2.1.0-beta3) and Lua 5.1.5 regarding the length (#) operator that I cannot understand.
>> 
>> Consider:
>> 
>> 
>> local a = {1, nil, nil, 2, nil, 3, nil, 4}
>> print(#a)
>> 
>> In both LuaJIT and Lua 5.1.5 the result is 8 (as expected).
>> 
>> This instead:
>> 
>> local a = {1, nil, 2, nil, 3, nil, 4}
>> print(#a)
>> 
>> Lua 5.1.5 gives 7 as result, LuaJIT gives 1. Is there a logic I cannot see?
>> 
>> Thanks