Module:Module introspection: Difference between revisions
m add module name to table |
bugfix non-modules being tracked as dependencies |
||
| Line 81: | Line 81: | ||
-- for that dependency (var), and, if applicable, the function used from | -- for that dependency (var), and, if applicable, the function used from | ||
-- that dependency. | -- that dependency. | ||
-- | -- Only consider dependencies that have "Module:" in its name | ||
for var, dep, func in code:gmatch([[local%s+([%w_]+)%s*=%s*require%(%s*["']([^"']+)["']%s*%)%.?([%w_%.]*)]]) do | for var, dep, func in code:gmatch([[local%s+([%w_]+)%s*=%s*require%(%s*["']([^"']+)["']%s*%)%.?([%w_%.]*)]]) do | ||
if func == "" then func = nil end | if dep:match("^Module:") then | ||
if func == "" then func = nil end | |||
deps[var] = { | |||
dep = dep, | |||
funcs = {}, | |||
direct_func = func | |||
} | |||
end | |||
end | end | ||
| Line 124: | Line 125: | ||
return deps | return deps | ||
end | |||
-- Helper function | |||
-- Find functions provided by a module, ignoring nested/local functions | |||
function p.find_functions(code) | |||
-- Iterate through file and find each function and the line found at | |||
local funcs = {} | |||
if code then | |||
local line_num = 0 | |||
for line in code:gmatch("([^\n]*)\n?") do -- Make sure gmatch does not skip blank lines | |||
line_num = line_num + 1 | |||
-- Match functions defined as function p.name( | |||
local name = line:match("function%s+[%w_]+%.([%w_]+)%s*%(") | |||
if name then | |||
table.insert(funcs, {name = name, line = line_num}) | |||
end | |||
-- Match functions defined as p.name = function( | |||
name = line:match("[%w_]+%.([%w_]+)%s*=%s*function%s*%(") | |||
if name then | |||
table.insert(funcs, {name = name, line = line_num}) | |||
end | |||
end | |||
end | |||
return funcs | |||
end | end | ||
| Line 164: | Line 193: | ||
-- Join all lines into a single string | -- Join all lines into a single string | ||
return table.concat(lines, "\n") | return table.concat(lines, "\n") | ||
end | end | ||