Implement coroutine handling

This commit is contained in:
Krzosa Karol
2024-08-14 12:41:09 +02:00
parent f38c20b975
commit 225d1ffc06
7 changed files with 45 additions and 62 deletions

View File

@@ -324,10 +324,24 @@ function ApplyRules(s)
return nil
end
Coroutines = {}
function AddCo(f)
local i = #Coroutines + 1
Coroutines[i] = coroutine.create(f)
return Coroutines[i]
end
function OnUpdate()
-- @todo: implement coroutine dispatch here
-- probably also want constatnly rerunning jobs with a set wake up time
-- @warning: make sure to not rewrite the thread list when rerunning this file
local new_co_list = {}
for key, co in pairs(Coroutines) do
local status = coroutine.status(co)
if status ~= "dead" then
coroutine.resume(co)
new_co_list[#new_co_list + 1] = co
end
end
Coroutines = new_co_list
end
)==";