Module:Introspection utils: Difference between revisions

Ganaram inukshuk (talk | contribs)
refactor invocation_exists to search through a table of invokes provided by find_invokes; will momentarily break other modules
Ganaram inukshuk (talk | contribs)
No edit summary
Line 329: Line 329:
-- of invocations, from find_invokes, and mod_name is the module name.
-- of invocations, from find_invokes, and mod_name is the module name.
function p.invocation_exists(invokes, mod_name)
function p.invocation_exists(invokes, mod_name)
-- Normalize module name
local normalize = function(name)
name = name or ""
name = name:gsub("_", " ")
name = name:lower()
name = name:gsub("^module:%s*", "")
return name
end
local target_mod = normalize(mod_name)
-- Search
for _, invoke in ipairs(invokes) do
for _, invoke in ipairs(invokes) do
if invoke.module == module_name then
local invoke_mod = normalize(invoke.module)
if not func_name or invoke.func == func_name then
if invoke_mod == target_mod then
return true
return true
end
end
end
end
end