pub fn wrap(f: function) -> functionExpand description
Creates a new coroutine with body f and returns a function that
resumes it each time it is called. Arguments to that function pass
into the coroutine, and its yielded values come back as results โ
but unlike resume, errors are propagated to the caller.
ยงExamples
local gen = coroutine.wrap(function()
for i = 1, 3 do coroutine.yield(i) end
end)
print(gen(), gen(), gen()) --> 1 2 3