Module:Module introspection: Difference between revisions

Ganaram inukshuk (talk | contribs)
add main function identification; bugfix comment removal so that it doesn't affect line numbers
Ganaram inukshuk (talk | contribs)
more bugfix
Line 9: Line 9:
-- Blanks comments but preserves line numbers
-- Blanks comments but preserves line numbers
function p.strip_comments(content)
function p.strip_comments(content)
    if not content then return "" end
if not content then return "" end


    -- Replace single-line comments with spaces
-- Blank single-line comments
    content = content:gsub("%-%-.*", function(s)
content = content:gsub("%-%-[^\n]*", function(s)
        return string.rep(" ", #s)
return string.rep(" ", #s)
    end)
end)


    -- Replace multi-line comments with spaces, preserving line breaks
-- Blank multi-line comments (handles --[[...]] and --[=[...]=])
    content = content:gsub("%-%-%[%[(.-)%]%]", function(s)
content = content:gsub("%-%-%[%[.-%]%]", function(s)
        local lines = {}
local blank = s:gsub("[^\n]", " ")
        for line in s:gmatch("([^\n]*)\n?") do
return blank
            table.insert(lines, string.rep(" ", #line))
end)
        end
content = content:gsub("%-%-%[%=[=]*%[.-%][=]*%]", function(s)
        return table.concat(lines, "\n")
local blank = s:gsub("[^\n]", " ")
    end)
return blank
end)


    return content
return content
end
end


Line 231: Line 232:
-- Call the introspection function
-- Call the introspection function
local dep_table, func_table = p._module_introspection({
local dep_table, func_table = p._module_introspection({
["module_name"]  = module_name       ,
["module_name"]  = module_name ,
["main_function"] = main_function_name,
["main_function"] = main_function,
})
})