Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function shell()
- dofile("rom/programs/shell")
- end
- local function pop(tab,index)
- local size = #tab
- tab[index] = nil
- for i=index+1,size do
- tab[i-1] = tab[i]
- tab[i] = nil
- end
- end
- threads = {}
- threads.main = {}
- threads.add = function(func,name)
- name = name or "[Untitled]"
- local threadid = coroutine.create(func)
- local threadTable = {}
- threadTable[1] = name
- threadTable[2] = threadid
- threads.main[#threads.main+1] = threadTable
- end
- threads.pullEvent = function(event)
- local ret = {coroutine.yield(event)}
- return table.unpack(ret)
- end
- threads.stop = function()
- coroutine.yield("end")
- end
- threads.run = function()
- os.queueEvent("start")
- while true do
- local event = {os.pullEventRaw())
- if threads[event[1]] then
- for i,v in pairs(threads[event[1]]) do
- local newEvent = coroutine.resume(v[2],table.unpack(event))
- if not newEvent then newEvent = "main" end
- if not (event[1] == newEvent) then
- if not threads[newEvent] then
- threads[newEvent] = {}
- end
- threads[newEvent][#threads[newEvent]+1] = v
- if newEvent == "main" then v[3] = false end
- pop(threads[event[1]],i)
- end
- end
- end
- for i,v in pairs(threads.main) do
- if v[3] == nil then v[3] = true end
- if v[3] then
- local newEvent = coroutine.resume(v[2],table.unpack(event))
- if not (newEvent == nil) then
- if not threads[newEvent] then
- threads[newEvent] = {}
- end
- threads[newEvent][#threads[newEvent]+1] = v
- pop(threads.main,i)
- end
- end
- v[3] = true
- end
- end
- end
- os.pullEvent = threads.pullEvent
- threads.add(function() dofile("rom/programs/shell") end)
- threads.run()
Advertisement
Add Comment
Please, Sign In to add comment