diff --git a/src/Hook.lua b/src/Hook.lua index 5765a12cb..cdb24d6f4 100644 --- a/src/Hook.lua +++ b/src/Hook.lua @@ -82,13 +82,19 @@ local validT = -- Checks for a valid hook name and stores it if valid. -- @param name The name of the hook. -- @param func The function to store with it. -function M.register(name, func) - if (validT[name] ~= nil) then - validT[name] = func +function M.register(name, func, append) + if (validT[name] ~= nil) then + -- 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 + validT[name][#validT[name]+1] = func + else + validT[name] = {func} + end else LmodWarning{msg="w_Unknown_Hook",name = tostring(name)} end - end -------------------------------------------------------------------------- @@ -97,7 +103,9 @@ end -- @return the results of the hook if it exists. function M.apply(name, ...) if (validT[name]) then - return validT[name](...) + for i=1,#validT[name] do + validT[name][i](...) + end end end