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