2017-10-23 18:59:47 +08:00
|
|
|
require("checkarg")
|
2017-10-23 18:38:37 +08:00
|
|
|
local event=require("event")
|
|
|
|
|
2017-10-23 18:59:47 +08:00
|
|
|
function AddEventListener(EventName,CallbackFunction)
|
|
|
|
checkstring(EventName)
|
|
|
|
checkfunction(CallbackFunction)
|
|
|
|
return event.listen(EventName,CallbackFunction)
|
2017-10-23 18:38:37 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function RemoveEventListener(ListenerID)
|
2017-10-23 18:59:47 +08:00
|
|
|
checknumber(ListenerID)
|
2017-10-23 18:38:37 +08:00
|
|
|
return event.ignore(event.handlers[ListenerID].key,event.handlers[ListenerID].callback)
|
2017-10-23 18:59:47 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function WaitEvent(EventName)
|
|
|
|
checkstring(EventName)
|
|
|
|
return event.pull(EventName)
|
|
|
|
end
|
|
|
|
|
|
|
|
function WaitEventFor(EventName,TimeOut)
|
|
|
|
checkstring(EventName)
|
|
|
|
checknumber(TimeOut)
|
|
|
|
return event.pull(TimeOut,EventName)
|
2017-10-23 19:09:15 +08:00
|
|
|
end
|
|
|
|
|
2017-10-23 19:42:40 +08:00
|
|
|
function PushEvent(EventName,...)
|
|
|
|
checkstring(EventName)
|
|
|
|
return event.push(EventName,...)
|
|
|
|
end
|
|
|
|
|
2017-10-23 19:09:15 +08:00
|
|
|
function AddTimer(Interval,CallbackFunction,Times)
|
|
|
|
checknumber(Interval)
|
|
|
|
checkfunction(CallbackFunction)
|
2017-10-25 22:18:52 +08:00
|
|
|
checknumber(Times)
|
|
|
|
if(Times<1) then -- Timer will infinitly run (when times <0)
|
|
|
|
return event.timer(Interval,CallbackFunction,math.huge)
|
|
|
|
else -- Timer will run [Times] times.
|
2017-10-23 19:09:15 +08:00
|
|
|
return event.timer(Interval,CallbackFunction,Times)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function RemoveTimer(TimerID)
|
|
|
|
checknumber(TimerID)
|
|
|
|
return event.cancel(TimerID)
|
|
|
|
end
|