lua-users home
lua-l archive

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




On 2018-03-16 07:00 AM, Oliver Kroth wrote:

Uh, the only issue is that ipairs would "respect" nil, but otherwise it does/should work.

But yes, being able to explicitly include nils in ipairs output, i.e. with __ipairs, would be nice.

afaIk, getting nil from the iterator is what terminates the loop...


ipairs uses nil as a loop end

e.g.

t = {1, 2, 3, nil, 4}

for k, v in ipairs(t) do print(k,v) end

--[[
1 1
2 2
3 3
--]]

When using __index, it still stops on the first nil. It doesn't respect __len.

This means tuples without nil in them would iterate fine:

for k, v in ipairs(tuple(1, 2, 3)) do print(k,v) end

--[[
1 1
2 2
3 3
--]]

But tuples with nil would stop short.

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.