Skip to content

Commit

Permalink
PR #696: Hook.apply now returns last result from hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert McLay committed Mar 10, 2024
1 parent d89e974 commit adda3df
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Hook.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function M.register(name, func, append)
-- set default for append to be backwards compatible
append = append or false
-- if append and validT[name] was set before, append. Otherwise, overwrite.
if append and validT[name] then
if (append and validT[name]) then
validT[name][#validT[name]+1] = func
else
validT[name] = {func}
Expand All @@ -102,11 +102,13 @@ end
-- @param name The name of the hook.
-- @return the results of the hook if it exists.
function M.apply(name, ...)
local result
if (validT[name]) then
for i=1,#validT[name] do
validT[name][i](...)
result = validT[name][i](...)
end
end
return result
end

function M.exists(name)
Expand Down

0 comments on commit adda3df

Please sign in to comment.