Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --#wrapper.lua
- tTask={}
- rTask={}
- rTask[1] = true
- rTask[2] = true
- rTask[3] = true
- ctask=0
- function Timed()
- while true do
- coroutine.yield()
- local event, timerID = os.pullEvent("timer")
- if timerID == tTask[1] then coroutine.resume(task1) end
- if timerID == tTask[2] then coroutine.resume(task2) end
- if timerID == tTask[3] then coroutine.resume(task3) end
- end
- end
- function Event()
- end
- function Launch()
- dofile("functions.lua")
- dofile("task.lua")
- end
- local t = coroutine.create(Timed)
- local e = coroutine.create(Event)
- local s = coroutine.create(Launch)
- while true do
- coroutine.resume(s,t)
- sleep(1)
- --print(os.clock())
- end
- --#task.lua
- function task1()
- for i=1,10 do
- a=2
- print(1)
- newSleep(3)
- end
- end
- function task2()
- for i=1,10 do
- print(2)
- coroutine.yield()
- end
- end
- function task3()
- for i=1,10 do
- print(3)
- coroutine.yield()
- end
- end
- t1 = coroutine.create(task1)
- t2 = coroutine.create(task2)
- t3 = coroutine.create(task3)
- while true do
- coroutine.yield()
- ctask = 1
- if rTask[1] == true then
- coroutine.resume(t1)
- print(coroutine.status(t1))
- end
- coroutine.yield()
- ctask = 2
- if rTask[2] == true then
- coroutine.resume(t2)
- print(coroutine.status(t2))
- end
- coroutine.yield()
- ctask = 3
- if rTask[3] == true then
- coroutine.resume(t3)
- print(coroutine.status(t3))
- end
- end
- --#functions.lua
- local OY = coroutine.yield
- --os.pullEvent = os.pullEventRaw
- local OPE = os.pullEvent
- --coroutine = {}
- function newYield()
- rTask[ctask] = true
- OY()
- end
- function newSleep(sec)
- tTask[ctask] = os.startTimer(sec)
- rTask[ctask] = false
- coroutine.yield()
- end
- --coroutine.yield = newYield
Advertisement
Add Comment
Please, Sign In to add comment