Guest User

startup

a guest
Mar 28th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.37 KB | None | 0 0
  1. local function shell()
  2.   dofile("rom/programs/shell")
  3. end
  4.  
  5. local function pop(tab,index)
  6.   local size = #tab
  7.   tab[index] = nil
  8.   for i=index+1,size do
  9.     tab[i-1] = tab[i]
  10.     tab[i] = nil
  11.   end
  12. end
  13.  
  14.  
  15. threads = {}
  16. threads.main = {}
  17.  
  18. threads.add = function(func,name)
  19.   name = name or "[Untitled]"
  20.   local threadid = coroutine.create(func)
  21.   local threadTable = {}
  22.   threadTable[1] = name
  23.   threadTable[2] = threadid
  24.   threads.main[#threads.main+1] = threadTable
  25. end
  26.  
  27. threads.pullEvent = function(event)
  28.   local ret = {coroutine.yield(event)}
  29.   return table.unpack(ret)
  30. end
  31.  
  32. threads.stop = function()
  33.   coroutine.yield("end")
  34. end
  35.  
  36. threads.run = function()
  37.   os.queueEvent("start")
  38.   while true do
  39.     local event = {os.pullEventRaw())
  40.     for i,v in pairs(threads.main) do
  41.       local newEvent = coroutine.resume(v[2],table.unpack(event))
  42.       if not (newEvent == nil) then
  43.         if not threads[newEvent] then
  44.           threads[newEvent] = {}
  45.         end
  46.         threads[newEvent][#threads[newEvent]+1] = v
  47.         pop(threads.main,i)
  48.       end
  49.     end
  50.     if threads[event[1]] then
  51.       for i,v in pairs(threads[event[1]]) do
  52.         local newEvent = coroutine.resume(v[2],table.unpack(event))
  53.         if not newEvent then newEvent      
  54.  
  55.  
  56. os.pullEvent = threads.pullEvent
  57. threads.add(function() dofile("rom/programs/shell") end)
Advertisement
Add Comment
Please, Sign In to add comment