Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local parallel = {}
- local function create(...)
- local tFns = table.pack(...)
- local tCos = {}
- for i = 1, tFns.n, 1 do
- local fn = tFns[i]
- if type(fn) ~= "function" then
- error("bad argument #" .. i .. " (expected function, got " .. type(fn) .. ")", 3)
- end
- tCos[i] = coroutine.create(fn)
- end
- return tCos
- end
- local function runUntilLimit(_routines, _limit)
- local count = #_routines
- local living = count
- local tFilters = {}
- local eventData = { n = 0 }
- while true do
- for n = 1, count do
- local r = _routines[n]
- if r then
- if tFilters[r] == eventData[1] or (tFilters[r] == nil and eventData[1] ~= "terminate") or (eventData[1] == "terminate" and n >= count) then
- local ok, param = coroutine.resume(r, table.unpack(eventData, 1, eventData.n))
- if not ok then
- error(param, 0)
- else
- tFilters[r] = param
- end
- if coroutine.status(r) == "dead" then
- _routines[n] = nil
- living = living - 1
- if living <= _limit then
- return n
- end
- end
- end
- end
- end
- for n = 1, count do
- local r = _routines[n]
- if r and coroutine.status(r) == "dead" then
- _routines[n] = nil
- living = living - 1
- if living <= _limit then
- return n
- end
- end
- end
- eventData = table.pack(os.pullEventRaw())
- end
- end
- function parallel.waitForAll(...)
- local routines = create(...)
- return runUntilLimit(routines, 0)
- end
- if fs.exists("/Hud/hudSettings") then
- os.loadAPI("/Hud/hudSettings")
- else
- local settingsFile = fs.open("/Hud/hudSettings","w")
- settingsFile.write([[
- --deleting any line in this file may
- --result in a crash , colors can be hex
- --in the format 0xRRGGBB
- x = 0
- y = 0
- scale = 1
- alpha = 0.733
- backgroundColor = 0x888888
- ]])
- settingsFile.close()
- os.loadAPI("/Hud/hudSettings")
- end
- _G.canvas = peripheral.call("back","canvas")
- canvas.clear()
- rednet.open("top")
- local Modules = fs.list("/Hud/Modules")
- for i, v in pairs(Modules) do
- Modules[i] = function ()
- shell.run("/Hud/Modules/"..v,v:sub(1,-5))
- end
- end
- table.insert(Modules, function() shell.run("shell") end)
- term.setCursorPos(1,1)
- term.clear()
- parallel.waitForAll(table.unpack(Modules))
Advertisement
Add Comment
Please, Sign In to add comment