Module:Module introspection: Difference between revisions
mNo edit summary |
add ability to add function descriptions |
||
| Line 221: | Line 221: | ||
-- Lists module's own functions; requires module name to produce links to each | -- Lists module's own functions; requires module name to produce links to each | ||
-- function. | -- function. | ||
function p.make_function_table(module_name, module_funcs, main_function) | function p.make_function_table(module_name, module_funcs, descriptions, main_function) | ||
local has_descriptions = descriptions ~= nil | |||
if has_descriptions then | |||
has_descriptions = has_descriptions and #descriptions > 0 | |||
end | |||
-- Table headers | -- Table headers | ||
| Line 231: | Line 236: | ||
table.insert(lines, "! Function") | table.insert(lines, "! Function") | ||
table.insert(lines, "! Params") | table.insert(lines, "! Params") | ||
-- If there are descriptions, add a column for that | |||
if has_descriptions then | |||
table.insert(lines, "! Description") | |||
end | |||
-- Table rows | -- Table rows | ||
| Line 262: | Line 272: | ||
table.insert(lines, "| " .. func) | table.insert(lines, "| " .. func) | ||
table.insert(lines, "| " .. params_string) | table.insert(lines, "| " .. params_string) | ||
if has_descriptions then | |||
table.insert(lines, "| %s", descriptions[info.name] or "") | |||
end | |||
end | end | ||
table.insert(lines, "|}") | table.insert(lines, "|}") | ||
| Line 277: | Line 291: | ||
local module_name = args["Module Name" ] | local module_name = args["Module Name" ] | ||
local main_function = args["Main Function"] | local main_function = args["Main Function"] | ||
local descriptions = args["Descriptions"] | |||
-- Preprocess module and blank-out comments | -- Preprocess module and blank-out comments | ||
| Line 289: | Line 304: | ||
-- Get module's functions, then build a table using that information | -- Get module's functions, then build a table using that information | ||
local module_funcs = p.find_functions(code) | local module_funcs = p.find_functions(code) | ||
local func_table = p.make_function_table(module_name, module_funcs, main_function) | local func_table = p.make_function_table(module_name, module_funcs, descriptions, main_function) | ||
-- Count the number of modules used | -- Count the number of modules used | ||
| Line 329: | Line 344: | ||
-- Process all function descriptions, if provided | -- Process all function descriptions, if provided | ||
local func_descriptions = {} | local func_descriptions = {} | ||
for | for key, val in pairs(args) do | ||
local func_name = key:match("^desc_([%w_]+)$") | |||
if func_name and val and val ~= "" then | |||
func_descriptions[func_name] = val | |||
end | |||
end | end | ||
| Line 337: | Line 355: | ||
["Module Name"] = module_name, | ["Module Name"] = module_name, | ||
["Main Function"] = main_function, | ["Main Function"] = main_function, | ||
["Descriptions"] = func_descriptions | |||
}) | }) | ||
end | end | ||
return p | return p | ||