Fix iterator.for_generator nil handling

This commit is contained in:
Lars Mueller 2022-09-07 12:02:51 +02:00
parent 5e7c29980d
commit 3c1f8a2d37

@ -1,5 +1,5 @@
local coroutine_create, coroutine_resume, coroutine_yield, coroutine_status, unpack
= coroutine.create, coroutine.resume, coroutine.yield, coroutine.status, unpack
local coroutine_create, coroutine_resume, coroutine_yield, coroutine_status, unpack, select
= coroutine.create, coroutine.resume, coroutine.yield, coroutine.status, unpack, select
local add = modlib.func.add
@ -23,7 +23,7 @@ function iterator.for_generator(caller, ...)
return coroutine_yield(...)
end, ...)
end)
local args = {...}
local args, n_args = {...}, select("#", ...)
return function()
if coroutine_status(co) == "dead" then
return
@ -34,7 +34,7 @@ function iterator.for_generator(caller, ...)
end
return ...
end
return _iterate(coroutine_resume(co, unpack(args)))
return _iterate(coroutine_resume(co, unpack(args, 1, n_args)))
end
end