Event queue

This commit is contained in:
InfiniteCoder
2024-03-07 22:33:08 +03:00
parent f8e02e1b3b
commit fcb420c4c7
7 changed files with 131 additions and 80 deletions
+20
View File
@@ -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)