Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function fIter (t, i)
- i = not i and #t or (i - 1)
- if i>0 then
- return i, t[i]
- end
- end
- local tBackground = setmetatable({},{
- __newindex = function(t,k,v)
- v = {cRoutine=coroutine.create(v[1]),sFilter=nil,sIdentifier=v[2]}
- rawset(t,k,v)
- end;
- })
- function add(fFunc,sIdentifier)
- tBackground[#tBackground+1] = {fFunc,sIdentifier}
- return tBackground[#tBackground]
- end
- function rem(cRoutine)
- cRoutine.sFilter="Daemon_internal_remove"
- end
- function getBackground()
- return tBackground
- end
- local bPullMeta = false
- function os.pullEventRaw(sEvent)
- local tData
- if bPullMeta then
- return coroutine.yield(sEvent)
- else
- repeat
- bPullMeta = true
- tData = {coroutine.yield()}
- for iIndex,cRoutine in fIter, tBackground do
- if cRoutine.sFilter==tData[1] or not cRoutine.sFilter then
- local bOk, sInnerEvent = coroutine.resume(cRoutine.cRoutine,unpack(tData))
- if bOk then
- cRoutine.sFilter = sInnerEvent
- else
- print(sInnerEvent)
- table.remove(tBackground,iIndex)
- end
- elseif cRoutine.sFilter=="Daemon_internal_remove" then
- table.remove(tBackground,iIndex)
- end
- end
- bPullMeta = false
- until tData[1] == sEvent or not sEvent
- return unpack(tData)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement