BrineUtil

Untitled

Feb 5th, 2021
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. local parallel = {}
  2. local function create(...)
  3. local tFns = table.pack(...)
  4. local tCos = {}
  5. for i = 1, tFns.n, 1 do
  6. local fn = tFns[i]
  7. if type(fn) ~= "function" then
  8. error("bad argument #" .. i .. " (expected function, got " .. type(fn) .. ")", 3)
  9. end
  10.  
  11. tCos[i] = coroutine.create(fn)
  12. end
  13.  
  14. return tCos
  15. end
  16.  
  17. local function runUntilLimit(_routines, _limit)
  18. local count = #_routines
  19. local living = count
  20.  
  21. local tFilters = {}
  22. local eventData = { n = 0 }
  23. while true do
  24. for n = 1, count do
  25. local r = _routines[n]
  26. if r then
  27. if tFilters[r] == eventData[1] or (tFilters[r] == nil and eventData[1] ~= "terminate") or (eventData[1] == "terminate" and n >= count) then
  28. local ok, param = coroutine.resume(r, table.unpack(eventData, 1, eventData.n))
  29. if not ok then
  30. error(param, 0)
  31. else
  32. tFilters[r] = param
  33. end
  34. if coroutine.status(r) == "dead" then
  35. _routines[n] = nil
  36. living = living - 1
  37. if living <= _limit then
  38. return n
  39. end
  40. end
  41. end
  42. end
  43. end
  44. for n = 1, count do
  45. local r = _routines[n]
  46. if r and coroutine.status(r) == "dead" then
  47. _routines[n] = nil
  48. living = living - 1
  49. if living <= _limit then
  50. return n
  51. end
  52. end
  53. end
  54. eventData = table.pack(os.pullEventRaw())
  55. end
  56. end
  57.  
  58. function parallel.waitForAll(...)
  59. local routines = create(...)
  60. return runUntilLimit(routines, 0)
  61. end
  62.  
  63. if fs.exists("/Hud/hudSettings") then
  64. os.loadAPI("/Hud/hudSettings")
  65. else
  66. local settingsFile = fs.open("/Hud/hudSettings","w")
  67. settingsFile.write([[
  68. --deleting any line in this file may
  69. --result in a crash , colors can be hex
  70. --in the format 0xRRGGBB
  71. x = 0
  72. y = 0
  73. scale = 1
  74. alpha = 0.733
  75. backgroundColor = 0x888888
  76.  
  77. ]])
  78. settingsFile.close()
  79. os.loadAPI("/Hud/hudSettings")
  80. end
  81. _G.canvas = peripheral.call("back","canvas")
  82. canvas.clear()
  83. rednet.open("top")
  84.  
  85. local Modules = fs.list("/Hud/Modules")
  86. for i, v in pairs(Modules) do
  87. Modules[i] = function ()
  88. shell.run("/Hud/Modules/"..v,v:sub(1,-5))
  89. end
  90. end
  91. table.insert(Modules, function() shell.run("shell") end)
  92.  
  93. term.setCursorPos(1,1)
  94. term.clear()
  95. parallel.waitForAll(table.unpack(Modules))
  96.  
Advertisement
Add Comment
Please, Sign In to add comment