Add check function for EventBusListen()

This commit is contained in:
Kirigaya Kazuto 2018-03-22 22:49:34 +08:00
parent 8fdb8a9ffa
commit 5f97697230

View File

@ -335,9 +335,20 @@ 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)
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)
@ -346,6 +357,7 @@ function EventBusListen(t,event_name)
)
)
end
end
function GetNextEvent(t,wait_second,wait_ratio)
checktable(t)