diff --git a/src/Hook.lua b/src/Hook.lua index 35b52ec9b..beed82879 100644 --- a/src/Hook.lua +++ b/src/Hook.lua @@ -76,6 +76,7 @@ local validT = reverseMapPathFilter = {}, -- This hook returns two arrays keepA, ignoreA to keep or -- ignore a path in the reverseMap mapping colorize_fullName = {}, -- Allow module avail and list to colorize name and/or version + add_to_module = {}, -- Allow dynamic additions to modules. The additions are still run through the sandbox. It passes the following table as a parameter {path, name, version, contents}. } local s_actionT = { append = true, prepend = true, replace = true } diff --git a/src/loadModuleFile.lua b/src/loadModuleFile.lua index 72f8091c1..ea33f909d 100644 --- a/src/loadModuleFile.lua +++ b/src/loadModuleFile.lua @@ -47,6 +47,7 @@ require("fileOps") require("sandbox") require("string_utils") require("utils") +local hook = require("Hook") local dbg = require("Dbg"):dbg() local concatTbl = table.concat local getenv = os.getenv @@ -152,6 +153,11 @@ function loadModuleFile(t) end end + -- dynamic additions via hook + local additional_lines = hook.apply("add_to_module", {path=myFileName(), name=myModuleName(), version=myModuleVersion(), contents=whole}) or {} + additional_lines = concatTbl(additional_lines, "\n") + whole = whole .. "\n" .. additional_lines + -- Use the sandbox to evaluate modulefile text. if (whole) then status, msg = sandbox_run(whole)