Module:Sandbox/Lemondoge/testFunctionify

local p = {}

function p.main(frame) -- undo sanitization local wikitext = frame.args[1] or '' if wikitext:match'nowiki' then wikitext = mw.text.unstripNoWiki(wikitext):gsub('&lt;', '<'):gsub('&gt;', '>') else error(" missing from first parameter") end local luaCode = frame.args[2] or '' local arrayParams = {} -- do the thing with f(a, b, c). thanks GPT-4 local function processString(input) local pattern = "f%((.-)%)" local arguments_str = input:match(pattern) local args = {} if arguments_str then for arg in arguments_str:gmatch("[^,]+") do           	arg = arg:gsub("^%s*(.-)%s*$", "%1")  -- remove leading and trailing spaces table.insert(args, arg) end end

for i, arg in ipairs(args) do           local key, value = arg:match("(%w+)=(%w+)") if key and value then arrayParams[key] = value else arrayParams[tostring(i)] = arg end end end processString(luaCode) local function replaceTripleBraces(parameter, _, default) -- extract corresponding arguments from the parent function if _ == "" then default = nil end -- mildly ugly hack for checking for return arrayParams[parameter] or default or "" end return frame:preprocess(wikitext:gsub("", replaceTripleBraces)) end

return p