Skip to content

Commit

Permalink
additional work for mode specific modfuncs
Browse files Browse the repository at this point in the history
  • Loading branch information
MCawood committed Nov 8, 2024
1 parent a1d7772 commit cb9878a
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 30 deletions.
4 changes: 4 additions & 0 deletions rt/unload/mf/Core/C/1.0.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
setenv{"A", "A", mode={"load"}}
setenv{"A", "B", mode={"unload"}}
setenv{"AA", "X", mode={"load", "unload"}}
prepend_path{"FOO", "BAR", mode={"unload", "load"}}
append_path{"X", "Y", mode={"unload"}}
load{"D", mode={"unload"}}
try_load{"J", mode={"unload"}}
2 changes: 2 additions & 0 deletions rt/unload/mf/Core/D/1.0.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
setenv("Z", "X")
setenv{"J", "K", mode={"load"}}
118 changes: 88 additions & 30 deletions src/modfuncs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,20 @@ end
--------------------------------------------------------------------------
-- Validate a function with only string table.
-- @param cmdName The command which is getting its arguments validated.
local function l_validateStringTable(n, cmdName, t)
n = max(n,#t)
local function l_validateStringTable(n, cmdName, table)
n = max(n,#table)
for i = 1, n do
local v = t[i]
local v = table[i]
if (type(v) ~= "string") then
mcp:report{msg="e_Args_Not_Strings", fn = myFileName(), cmdName = cmdName}
return false
end
end
if (t.priority ~= nil) then
if (table.priority ~= nil) then
local valid = false
if (t.priority == 0) then
if (table.priority == 0) then
valid = true
elseif (t.priority >= 10) then
elseif (table.priority >= 10) then
valid = true
end

Expand Down Expand Up @@ -162,6 +162,8 @@ end
-- Validate a function with only string module names table.
-- @param cmdName The command which is getting its arguments validated.
local function l_validateModules(cmdName, ...)

dbg.print{"validateModules input BLAH: ", l_concatTbl({...},", "),")"}
local argA = pack(...)
--dbg.print{"l_validateModules: cmd: ",cmdName, " argA.n: ",argA.n,"\n"}
local allGood = true
Expand Down Expand Up @@ -189,10 +191,19 @@ end
-- "load('name'); load('name/1.2'); load(atleast('name','3.2'))",
function load_module(...)
dbg.start{"load_module(",l_concatTbl({...},", "),")"}
if (not l_validateModules("load",...)) then return {} end

local table
local mcp_old = mcp
mcp, table = list_2_Tbl(MCP, mcp, ...)
if ( not mcp ) then
mcp = mcp_old
return
end

if (not l_validateModules("load", table)) then return {} end

dbg.print{"mcp:name(): ",mcp:name(),"\n"}
local b = mcp:load_usr(MName:buildA(mcp:MNameType(), ...))
local b = mcp:load_usr(MName:buildA(mcp:MNameType(), table))
dbg.fini("load_module")
return b
end
Expand All @@ -208,9 +219,18 @@ end

function load_any(...)
dbg.start{"load_any(",l_concatTbl({...},", "),")"}
if (not l_validateModules("load_any",...)) then return {} end

local b = mcp:load_any(MName:buildA(mcp:MNameType(), ...))
local table
local mcp_old = mcp
mcp, table = list_2_Tbl(MCP, mcp, ...)
if ( not mcp ) then
mcp = mcp_old
return
end

if (not l_validateModules("load_any", table)) then return {} end

local b = mcp:load_any(MName:buildA(mcp:MNameType(), table))
dbg.fini("load_any")
return b
end
Expand Down Expand Up @@ -254,34 +274,55 @@ end
--------------------------------------------------------------------------
-- Prepend a value to a path like variable.
function prepend_path(...)
local t = l_convert2table(...)
dbg.start{"prepend_path(",l_concatTbl(t,", "),")"}
if (not l_validateStringTable(2, "prepend_path",t)) then return end

l_cleanupPathArgs(t)
if (t[2]) then mcp:prepend_path(t) end
local table
local mcp_old = mcp
mcp, table = list_2_Tbl(MCP, mcp, ...)
dbg.start{"prepend_path(",l_concatTbl(table,", "),")"}
if ( not mcp ) then
mcp = mcp_old
return
end

if (not l_validateStringTable(2, "prepend_path", table)) then return end
l_cleanupPathArgs(table)
if (table[2]) then mcp:prepend_path(table) end
mcp = mcp_old
dbg.fini("prepend_path")
end

--------------------------------------------------------------------------
-- Append a value to a path like variable.
function append_path(...)
local t = l_convert2table(...)
dbg.start{"append_path(",l_concatTbl(t,", "),")"}
if (not l_validateStringTable(2, "append_path",t)) then return end
l_cleanupPathArgs(t)
if (t[2]) then mcp:append_path(t) end
local table
local mcp_old = mcp
mcp, table = list_2_Tbl(MCP, mcp, ...)
dbg.start{"append_path(",l_concatTbl(table,", "),")"}
if ( not mcp ) then
mcp = mcp_old
return
end

if (not l_validateStringTable(2, "append_path",table)) then return end
l_cleanupPathArgs(table)
if (table[2]) then mcp:append_path(table) end
dbg.fini("append_path")
end

--------------------------------------------------------------------------
-- Remove a value from a path like variable.
function remove_path(...)
local t = l_convert2table(...)
dbg.start{"remove_path(",l_concatTbl(t,", "),")"}
if (not l_validateStringTable(2, "remove_path",t)) then return end
l_cleanupPathArgs(t)
if (t[2]) then mcp:remove_path(t) end
local table
local mcp_old = mcp
mcp, table = list_2_Tbl(MCP, mcp, ...)
dbg.start{"remove_path(",l_concatTbl(table,", "),")"}
if ( not mcp ) then
mcp = mcp_old
return
end

if (not l_validateStringTable(2, "remove_path", table)) then return end
l_cleanupPathArgs(table)
if (table[2]) then mcp:remove_path(table) end
dbg.fini("remove_path")
end

Expand Down Expand Up @@ -848,9 +889,18 @@ end
-- will not produce a warning if the specified modulefile(s) do not exist.
function try_load(...)
dbg.start{"try_load(",l_concatTbl({...},", "),")"}
if (not l_validateModules("try_load",...)) then return {} end

local b = mcp:try_load(MName:buildA(mcp:MNameType(), ...))
local table
local mcp_old = mcp
mcp, table = list_2_Tbl(MCP, mcp, ...)
if ( not mcp ) then
mcp = mcp_old
return
end

if (not l_validateModules("try_load", table)) then return {} end

local b = mcp:try_load(MName:buildA(mcp:MNameType(), table))
dbg.fini("try_load")
return b
end
Expand Down Expand Up @@ -889,8 +939,16 @@ end
-- not loaded. The reverse of an unload is a no-op.
function unload(...)
dbg.start{"unload(",l_concatTbl({...},", "),")"}
if (not l_validateModules("unload",...)) then return {} end
local b = unload_internal(MName:buildA("mt",...))
local table
local mcp_old = mcp
mcp, table = list_2_Tbl(MCP, mcp, ...)
if ( not mcp ) then
mcp = mcp_old
return
end

if (not l_validateModules("unload", table)) then return {} end
local b = unload_internal(MName:buildA("mt", table))
dbg.fini("unload")
return b
end
Expand Down

0 comments on commit cb9878a

Please sign in to comment.