Module:Test2: Difference between revisions
From Elwiki
No edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
function p.Patch(frame) | function p.Patch(frame) | ||
local | local origArgs = {} | ||
local orig = frame.args.orig or "" | |||
orig = orig:gsub("<nowiki>(.-)</nowiki>", function(args) | |||
for k, v in args:gmatch("|%s*(.-)%s*=%s*(.-)%s*|") do | |||
origArgs[k] = v | |||
end | |||
return "" | |||
end) | |||
local newArgs = {} | local newArgs = {} | ||
for k, v in pairs(frame.args) do | for k, v in pairs(frame.args) do | ||
Line 10: | Line 17: | ||
end | end | ||
end | end | ||
-- Merge the old and new arguments | -- Merge the old and new arguments | ||
local mergedArgs = {} | local mergedArgs = {} | ||
for k, v in pairs( | for k, v in pairs(origArgs) do | ||
mergedArgs[k] = v | mergedArgs[k] = v | ||
end | end | ||
Line 26: | Line 27: | ||
end | end | ||
-- | -- Call the Damage template with the merged arguments | ||
local | local damageTemplate = mw.getCurrentFrame():expandTemplate{ title = "Damage", args = mergedArgs } | ||
return | return damageTemplate | ||
end | end | ||
return p | return p |
Revision as of 20:01, 25 April 2023
Documentation for this module may be created at Module:Test2/doc
local p = {}
function p.Patch(frame)
local origArgs = {}
local orig = frame.args.orig or ""
orig = orig:gsub("<nowiki>(.-)</nowiki>", function(args)
for k, v in args:gmatch("|%s*(.-)%s*=%s*(.-)%s*|") do
origArgs[k] = v
end
return ""
end)
local newArgs = {}
for k, v in pairs(frame.args) do
if k ~= "orig" then
newArgs[k] = v
end
end
-- Merge the old and new arguments
local mergedArgs = {}
for k, v in pairs(origArgs) do
mergedArgs[k] = v
end
for k, v in pairs(newArgs) do
mergedArgs[k] = v
end
-- Call the Damage template with the merged arguments
local damageTemplate = mw.getCurrentFrame():expandTemplate{ title = "Damage", args = mergedArgs }
return damageTemplate
end
return p