43 lines
681 B
Lua
43 lines
681 B
Lua
|
local coroutines={}
|
||
|
|
||
|
local _cocounter = 0
|
||
|
local _cocreate = cocreate
|
||
|
|
||
|
function cocreate(fn)
|
||
|
_cocounter += 1
|
||
|
k = k or _cocounter
|
||
|
coroutines[_cocounter] = _cocreate(fn, k)
|
||
|
return coroutines[_cocounter], _cocounter
|
||
|
end
|
||
|
|
||
|
function getcoroutine(key)
|
||
|
return coroutines[key]
|
||
|
end
|
||
|
|
||
|
function stepcoroutine(key)
|
||
|
coresume(coroutines[key])
|
||
|
end
|
||
|
|
||
|
function stopcoroutine(key)
|
||
|
coroutines[key] = nil
|
||
|
end
|
||
|
|
||
|
function _coresolve()
|
||
|
for k,co in pairs(coroutines) do
|
||
|
if costatus(co)!='dead' then
|
||
|
coresume(co)
|
||
|
else
|
||
|
stopcoroutine(k)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function wait(seconds)
|
||
|
wait_frames(seconds*60)
|
||
|
end
|
||
|
|
||
|
function wait_frames(frames)
|
||
|
for i=1,frames do
|
||
|
yield()
|
||
|
end
|
||
|
end
|