Files
Halyde/halyde/core/cormgr.lua
T
2026-04-30 15:09:56 +00:00

1 line
1.5 KiB
Lua

_G.cormgr={}_G.cormgr.corList={}_G.cormgr.labelList={}local a=import("component")local b=import("filesystem")local c=import("json")local a=a.gpu;function _G.cormgr.loadCoroutine(b,...)local c={...}local function d()local b,c=xpcall(function(...)import(...)end,function(a)return a.."\n \n"..debug.traceback()end,b,table.unpack(c))if not b then if print then a.freeAllBuffers()print("\n\27[91m"..c)else error(c)end end end;cormgr.addCoroutine(d,string.match(tostring(b),"([^/]+)%.lua$"))end;function _G.cormgr.addCoroutine(a,b)local a=coroutine.create(a)table.insert(cormgr.corList,a)table.insert(cormgr.labelList,b)return a end;function _G.cormgr.removeCoroutine(a)local a=table.find(cormgr.labelList,cor)table.remove(cormgr.corList,a)table.remove(cormgr.labelList,a)end;function handleError(a)if a==nil then error("unknown error")else error(tostring(a).."\n \n"..debug.traceback())end end;local function a()for a=1,#_G.cormgr.corList do if cormgr.corList[a]then local b,c=coroutine.resume(cormgr.corList[a])if cormgr.corList[a]then if not b then handleError(c)end;if coroutine.status(cormgr.corList[a])=="dead"then table.remove(cormgr.corList,a)table.remove(cormgr.labelList,a)a=a-1 end end end end end;local b,d,e=b.open("/halyde/config/startupapps.json","r"),"",nil;repeat e=b:read(math.huge or math.maxinteger)d=d..(e or"")until not e;b:close()for b,b in ipairs(c.decode(d))do if b~=""then _G.cormgr.loadCoroutine(b)a()end end;while true do a()if#_G.cormgr.corList==0 then computer.shutdown()end end