-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheventLib.lua
More file actions
47 lines (34 loc) · 957 Bytes
/
eventLib.lua
File metadata and controls
47 lines (34 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
---@class EventLibAPI
local EventLibAPI = {}
EventLibAPI.__index = EventLibAPI
function EventLibAPI.new()
return setmetatable({}, EventLibAPI)
end
EventLibAPI.newEvent = EventLibAPI.new
function EventLibAPI:register(func, name)
self[name or func] = func
end
function EventLibAPI:clear()
for key in pairs(self) do self[key] = nil end
end
function EventLibAPI:remove(name)
self[name] = nil
end
function EventLibAPI:getRegisteredCount() return #self end
function EventLibAPI:__len() return #self end
function EventLibAPI:__call(...)
local flush = {}
for _, func in pairs(self) do
flush[#flush+1] = {func(...)}
end
return flush
end
---@type fun(self: EventLibAPI, ...: any): any[]
EventLibAPI.invoke = EventLibAPI.__call
function EventLibAPI.__index(t, i)
return rawget(t,i)or rawget(t,i:upper()) or EventLibAPI[i]
end
function EventLibAPI.__newindex(t, i, v)
rawset(t,type(i) == "string" and t[i:upper()] or i,v)
end
return EventLibAPI