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