Module:Module introspection: Difference between revisions
m bugfix worked too well, now it thinks it doesnt use arguments when it does Tag: Reverted |
rollback for now Tag: Manual revert |
||
| Line 58: | Line 58: | ||
-- them itself by calling list_dependencies | -- them itself by calling list_dependencies | ||
function p.list_dependency_functions(module_name, deps) | function p.list_dependency_functions(module_name, deps) | ||
local module_name = module_name --or "MOS" -- Test arg; comment out when not testing | |||
-- Get dependencies | |||
local deps = p.list_dependencies(module_name) | |||
-- Load module | |||
local title = mw.title.new('Module:' .. module_name) | local title = mw.title.new('Module:' .. module_name) | ||
local content = | local content = title:getContent() | ||
-- Step 1: | -- Step 1: Find all require statements with optional .function | ||
local results = {} | local results = {} | ||
for var, dep, entry in content:gmatch( | |||
"local%s+([%w_]+)%s*=%s*require%s*%(%s*['\"]Module:(.-)['\"]%s*%)%.?([%w_]*)" | |||
) do | |||
local used = {} | |||
-- Step 2: Check how it's used | |||
if entry ~= "" then | |||
-- The module returned a single function: var() usage | |||
for _ in content:gmatch(var .. "%s*%(") do | |||
used[entry] = true | |||
end | end | ||
else | |||
-- | -- The variable is a module table: var.func() usage | ||
for | for func in content:gmatch(var .. "%.(%w+)%s*%(") do | ||
used[func] = true | |||
end | end | ||
end | |||
-- Step 3: Build result entry | |||
local funcList = {} | |||
for f in pairs(used) do table.insert(funcList, f) end | |||
table.sort(funcList) | |||
results[dep] = results[dep] or {} | |||
table.insert(results[dep], { | |||
variable = var, | |||
entry = (entry ~= "" and entry or nil), | |||
functions = funcList | |||
}) | |||
end | end | ||