pico8-0hh1/coroutines.lua
2022-06-02 22:39:23 +02:00

34 lines
511 B
Lua

local coroutines={}
-- starts a coroutine and returns its key
function startcoroutine(fn, key)
add(coroutines, fn)
end
function stepcoroutine(fn)
coresume(fn)
end
function stopcoroutine(fn)
del(coroutines, fn)
end
function _coresolve()
for co in all(coroutines) do
if costatus(co)!='dead' then
assert(coresume(co))
else
stopcoroutine(co)
end
end
end
function wait(seconds)
wait_frames(seconds*60)
end
function wait_frames(frames)
for i=1,frames do
yield()
end
end