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
14
libevent.lua
14
libevent.lua
|
@ -335,9 +335,20 @@ end
|
||||||
|
|
||||||
--- EventBus: Queued event bus.
|
--- EventBus: Queued event bus.
|
||||||
--- Notice that event bus can only handle event packages.
|
--- Notice that event bus can only handle event packages.
|
||||||
function EventBusListen(t,event_name)
|
function EventBusListen(t,event_name,checkfn)
|
||||||
checktable(t)
|
checktable(t)
|
||||||
checkstring(event_name)
|
checkstring(event_name)
|
||||||
|
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,
|
table.insert(t.listeners,
|
||||||
AddEventListener(event_name,
|
AddEventListener(event_name,
|
||||||
function(epack)
|
function(epack)
|
||||||
|
@ -345,6 +356,7 @@ function EventBusListen(t,event_name)
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function GetNextEvent(t,wait_second,wait_ratio)
|
function GetNextEvent(t,wait_second,wait_ratio)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user