123456789101112131415161718192021222324252627282930313233343536373839404142 |
- os.loadAPI("/lib/util")
-
- function Prog()
- local self = {}
- util.makeEventListener(self)
-
- local running = true
-
- local timeouts = {}
-
- self.init = function()
- self.emit("init")
- while running do
- evt, a, b, c, d, e = os.pullEvent()
-
- if evt == "timer" and timeouts[a] then
- timeouts[a]()
- else
- self.emit(evt, a, b, c, d, e)
- end
- end
- end
-
- self.exit = function()
- self.emit("exit")
- running = false
- os.startTimer(0)
- end
-
- self.setTimeout = function(time, cb)
- local id = os.startTimer(time)
- timeouts[id] = cb
- return id
- end
-
- self.cancelTimeout = function(id)
- os.cancelTimer(id)
- timeouts[id] = nil
- end
-
- return self
- end
|