Module:Module introspection: Difference between revisions
testing... |
introspection should now ignore strings, on the offchance that strings contain code |
||
| Line 18: | Line 18: | ||
-- generally provides functionality to other modules. | -- generally provides functionality to other modules. | ||
-- Inspects a module for its functions, its dependencies, and the functions used | -- Inspects a module for its functions, its dependencies, and the functions used | ||
| Line 95: | Line 67: | ||
return table.concat(lines, "\n") | return table.concat(lines, "\n") | ||
end | end | ||
-- Helper function | |||
-- Blanks strings while preserving line numbers | |||
function p.strip_strings(code) | |||
-- Blank double-quoted strings | |||
code = code:gsub('"(.-)"', function(s) | |||
return string.rep(" ", #s + 2) -- +2 for the quotes | |||
end) | |||
-- Blank single-quoted strings | |||
code = code:gsub("'(.-)'", function(s) | |||
return string.rep(" ", #s + 2) | |||
end) | |||
-- Blank long bracketed strings [[...]] | |||
code = code:gsub("%[%[(.-)%]%]", function(s) | |||
-- Preserve line breaks | |||
local blanks = s:gsub(".", " ") | |||
local newlines = s:gsub("[^\n]", " ") | |||
return blanks .. "]" .. "]" | |||
end) | |||
return code | |||
end | |||
-- Helper function | -- Helper function | ||
| Line 261: | Line 258: | ||
local code = title:getContent() | local code = title:getContent() | ||
code = p.strip_comments(code) -- Blank-out comments | code = p.strip_comments(code) -- Blank-out comments | ||
code = p.strip_strings(code) -- Blank out strings | |||
-- Get dependencies and their functions used, then build a table | -- Get dependencies and their functions used, then build a table | ||