mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
Event queue
This commit is contained in:
parent
f8e02e1b3b
commit
fcb420c4c7
7 changed files with 131 additions and 80 deletions
|
|
@ -120,6 +120,26 @@ function color_mt.__tostring(self)
|
|||
return "rgba("..self[1]..", "..self[2]..", "..self[3]..", "..self[4]..")"
|
||||
end
|
||||
|
||||
-- events
|
||||
events = {
|
||||
handlers = {}
|
||||
}
|
||||
|
||||
function events.on(event, func)
|
||||
events.handlers[event] = events.handlers[event] or {}
|
||||
table.insert(events.handlers[event], func)
|
||||
end
|
||||
|
||||
function events.emit(event, ...)
|
||||
result = nil
|
||||
if events.handlers[event] then
|
||||
for _, func in ipairs(events.handlers[event]) do
|
||||
result = result or func(...)
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
-- class designed for simple UI-nodes access via properties syntax
|
||||
local Element = {}
|
||||
function Element.new(docname, name)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue