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