Skip to content

Commit

Permalink
Added new 'add_to_module' hook.
Browse files Browse the repository at this point in the history
  • Loading branch information
AcerP-py committed Dec 12, 2024
1 parent 9e2b344 commit e6f13fb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Hook.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
6 changes: 6 additions & 0 deletions src/loadModuleFile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e6f13fb

Please sign in to comment.