Jump to content

Module:IncrementParams

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 04:54, 13 June 2013 (copy infobox incrementing function fromModule:User:Mr. Stradivarius/sandbox, with a few tweaks). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

local p = {}
local increment
 
local function replace(ws1, param, num, ws2)
    return '|' .. ws1 .. param .. tostring(tonumber(num) + increment) .. ws2 .. '='
end
 
function p.main(frame)
    increment = tonumber(frame.args.increment) or 1
    itext = frame.args[1] or ''
    itext = mw.ustring.gsub(itext, '|(%s*)(%a+)([1-9]%d*)(%s*)=', replace)
    return itext
end
 
return p