Module:Module introspection: Difference between revisions
mNo edit summary |
todo |
||
| Line 13: | Line 13: | ||
-- - If neither function exists, then the module is a metamodule, a module that | -- - If neither function exists, then the module is a metamodule, a module that | ||
-- generally provides functionality to other modules. | -- generally provides functionality to other modules. | ||
-- TODO: bugfix dependency usage | |||
-- The following snippet should detect use of any dependency, but it should be | |||
-- cross-referenced with the found dependencies | |||
--[[ | |||
for match in code:gmatch("([_%a][_%w%.]*)%s*%(") do | |||
print(match) | |||
end | |||
]]-- | |||
-- 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 65: | Line 74: | ||
-- Helper function | -- Helper function | ||
-- Find dependencies for a module, given a preprocessed module's code | -- Find dependencies for a module, given a preprocessed module's code | ||
-- This returns a table of module names | |||
-- TODO: refactor so it pairs module names with their corresponding variable | |||
-- name; EG, for the line: | |||
-- local med = require("Module:Mediants") | |||
-- the entry in the table is ["Mediants"] = "med"; ALTERNATIVELY, return a table | |||
-- of two-entry tables, such that each two-entry table consists of module-var | |||
-- pairs, such as { "Mediants", "med" }; this is to allow sorting. | |||
function p.find_dependencies(preprocessed_module) | function p.find_dependencies(preprocessed_module) | ||
local deps = {} | local deps = {} | ||
| Line 75: | Line 91: | ||
-- Helper function | -- Helper function | ||
-- Find functions used by each dependency | -- Find functions used by each dependency | ||
-- TODO: refactor so it references a table produced by the above function. | |||
-- By matching strings of the form "([_%a][_%w%.]*)%s*%(", it can determine | |||
-- what dependency is being used. Table produced should have entries in this | |||
-- form: | |||
-- ["med"] = { "find_mediants", "find_deepest" } | |||
-- Each entry in that smaller table is a function that was used | |||
function p.find_dependency_functions(preprocessed_module) | function p.find_dependency_functions(preprocessed_module) | ||