mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
update events & update some built-in events codes
This commit is contained in:
parent
b3e29b012d
commit
72d5eca632
3 changed files with 31 additions and 24 deletions
|
|
@ -17,7 +17,10 @@ events = {
|
|||
}
|
||||
|
||||
function events.on(event, func)
|
||||
events.handlers[event] = func
|
||||
if events.handlers[event] == nil then
|
||||
events.handlers[event] = {}
|
||||
end
|
||||
table.insert(events.handlers[event], func)
|
||||
end
|
||||
|
||||
function events.remove_by_prefix(prefix)
|
||||
|
|
@ -37,9 +40,13 @@ function pack.unload(prefix)
|
|||
end
|
||||
|
||||
function events.emit(event, ...)
|
||||
result = nil
|
||||
if events.handlers[event] then
|
||||
result = result or events.handlers[event](...)
|
||||
local result = nil
|
||||
local handlers = events.handlers[event]
|
||||
if handlers == nil then
|
||||
return nil
|
||||
end
|
||||
for _, func in ipairs(handlers) do
|
||||
result = result or func(...)
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue