mirror of
https://github.com/Kiritow/OpenComputerScripts.git
synced 2024-03-22 13:10:46 +08:00
Add check function for EventBusListen()
This commit is contained in:
parent
8fdb8a9ffa
commit
5f97697230
26
libevent.lua
26
libevent.lua
|
@ -335,16 +335,28 @@ end
|
|||
|
||||
--- EventBus: Queued event bus.
|
||||
--- Notice that event bus can only handle event packages.
|
||||
function EventBusListen(t,event_name)
|
||||
function EventBusListen(t,event_name,checkfn)
|
||||
checktable(t)
|
||||
checkstring(event_name)
|
||||
table.insert(t.listeners,
|
||||
AddEventListener(event_name,
|
||||
function(epack)
|
||||
table.insert(t.events,epack)
|
||||
end
|
||||
if(checkfn~=nil and type(checkfn)=="function") then
|
||||
table.insert(t.listeners,
|
||||
AddEventListener(event_name,
|
||||
function(epack)
|
||||
if(checkfn(epack)) then
|
||||
table.insert(t.events,epack)
|
||||
end
|
||||
end
|
||||
)
|
||||
)
|
||||
)
|
||||
else
|
||||
table.insert(t.listeners,
|
||||
AddEventListener(event_name,
|
||||
function(epack)
|
||||
table.insert(t.events,epack)
|
||||
end
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
function GetNextEvent(t,wait_second,wait_ratio)
|
||||
|
|
Loading…
Reference in New Issue
Block a user