2021-11-13 21:59:31 +05:30
|
|
|
local hooks, M = {}, {}
|
2021-11-14 12:43:36 +05:30
|
|
|
|
2021-08-24 21:45:59 +02:00
|
|
|
local allowed_hooks = {
|
2021-12-11 01:49:35 +05:30
|
|
|
["install_plugins"] = true,
|
|
|
|
["setup_mappings"] = true,
|
|
|
|
["ready"] = true,
|
2021-08-24 21:45:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
M.add = function(name, fn)
|
2021-12-11 01:49:35 +05:30
|
|
|
if not allowed_hooks[name] then
|
2021-11-13 21:59:31 +05:30
|
|
|
print("Custom lua uses unallowed hook " .. name)
|
2021-10-02 10:45:50 +05:30
|
|
|
end
|
2021-12-11 01:49:35 +05:30
|
|
|
if not hooks[name] then
|
2021-10-02 10:45:50 +05:30
|
|
|
hooks[name] = {}
|
|
|
|
end
|
|
|
|
table.insert(hooks[name], fn)
|
2021-08-24 21:45:59 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
M.run = function(name, args)
|
2021-12-11 01:49:35 +05:30
|
|
|
if hooks[name] then
|
2021-11-13 21:59:31 +05:30
|
|
|
for _, hook in pairs(hooks[name]) do
|
|
|
|
hook(args)
|
2021-08-31 16:20:57 +02:00
|
|
|
end
|
2021-10-02 10:45:50 +05:30
|
|
|
end
|
2021-08-31 16:20:57 +02:00
|
|
|
end
|
|
|
|
|
2021-10-02 10:45:50 +05:30
|
|
|
return M
|