|
|
@ -14,10 +14,10 @@ envBase.kitn = {}
|
|
|
|
envBase._G, envBase.load = nil
|
|
|
|
envBase._G, envBase.load = nil
|
|
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
do
|
|
|
|
--[[propogating os yields
|
|
|
|
--[[propagating os yields
|
|
|
|
when a process calls coroutine.yield(), we prepend `false` to the yielded values. os yields start with a truthy value.
|
|
|
|
when a process calls coroutine.yield(), we prepend `false` to the yielded values. os yields start with a truthy value.
|
|
|
|
in coroutine.resume(), if the coroutine yielded (ie isn't dead) and the first value is truthy (ie an os yield),
|
|
|
|
in coroutine.resume(), if the coroutine yielded (ie isn't dead) and the first value is truthy (ie an os yield),
|
|
|
|
we also yield the current coroutine, unwinding the current stack of running coroutines back to the os thread.
|
|
|
|
we also yield from the current coroutine, unwinding the stack of running coroutines back to the os thread.
|
|
|
|
when the current coroutine is resumed, we pass the values back into the inner coroutine and repeat.
|
|
|
|
when the current coroutine is resumed, we pass the values back into the inner coroutine and repeat.
|
|
|
|
]]
|
|
|
|
]]
|
|
|
|
envBase.coroutine.yield = function(...) return kyield(false, ...) end
|
|
|
|
envBase.coroutine.yield = function(...) return kyield(false, ...) end
|
|
|
@ -30,9 +30,9 @@ do
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function forwardYield(co, ok, ...)
|
|
|
|
function forwardYield(co, ok, ...)
|
|
|
|
if co_status(co) ~= 'suspended' then --it's not a sysyield if the coroutine didn't yield (because it returned/errored)
|
|
|
|
if co_status(co) ~= 'suspended' then --not an os yield if the coroutine didn't yield (because it returned/errored)
|
|
|
|
return ok, ...
|
|
|
|
return ok, ...
|
|
|
|
elseif (...) then --firest arg is truthy for os yield, false for coroutine.yield()
|
|
|
|
elseif (...) then --first arg is truthy for os yield, false for coroutine.yield()
|
|
|
|
--yield to the scheduler, pass the results (ie signal) back to `co`, then repeat for `co`'s next yield
|
|
|
|
--yield to the scheduler, pass the results (ie signal) back to `co`, then repeat for `co`'s next yield
|
|
|
|
return forwardYield(co, kresume(co, kyield(...)))
|
|
|
|
return forwardYield(co, kresume(co, kyield(...)))
|
|
|
|
else --`co` called coroutine.yield(), so return its values to the waiting coroutine.resume()
|
|
|
|
else --`co` called coroutine.yield(), so return its values to the waiting coroutine.resume()
|
|
|
|