OpenComputerScripts/libevent.lua

24 lines
622 B
Lua
Raw Normal View History

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 18:38:37 +08:00
end