cleanup!
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
local hooks, overrides, M = {}, {}, {}
|
||||
local hooks, M = {}, {}
|
||||
local allowed_hooks = {
|
||||
"install_plugins",
|
||||
"setup_mappings",
|
||||
@@ -11,13 +11,11 @@ local function has_value(tab, val)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
M.add = function(name, fn)
|
||||
if not (has_value(allowed_hooks, name)) then
|
||||
error("Custom lua uses unallowed hook " .. name)
|
||||
print("Custom lua uses unallowed hook " .. name)
|
||||
end
|
||||
if hooks[name] == nil then
|
||||
hooks[name] = {}
|
||||
@@ -26,43 +24,11 @@ M.add = function(name, fn)
|
||||
end
|
||||
|
||||
M.run = function(name, args)
|
||||
if hooks[name] == nil then
|
||||
return
|
||||
end
|
||||
|
||||
for _, hook in pairs(hooks[name]) do
|
||||
hook(args)
|
||||
end
|
||||
end
|
||||
|
||||
M.createOverrides = function(module)
|
||||
local O = {}
|
||||
|
||||
O.get = function(name, default)
|
||||
local current = default
|
||||
if overrides[module] and overrides[module][name] then
|
||||
if type(overrides[module][name]) == "function" then
|
||||
current = overrides[module][name]
|
||||
elseif type(overrides[module][name]) == "table" then
|
||||
for _, override in pairs(overrides[module][name]) do
|
||||
current = override(current)
|
||||
end
|
||||
end
|
||||
if hooks[name] ~= nil then
|
||||
for _, hook in pairs(hooks[name]) do
|
||||
hook(args)
|
||||
end
|
||||
return current
|
||||
end
|
||||
|
||||
return O
|
||||
end
|
||||
|
||||
M.override = function(module, name, overwrite)
|
||||
if overrides[module] == nil then
|
||||
overrides[module] = {}
|
||||
end
|
||||
if overrides[module][name] == nil then
|
||||
overrides[module][name] = {}
|
||||
end
|
||||
table.insert(overrides[module][name], overwrite)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user