Anonymous user
Module:For loop: Difference between revisions
require Module:Template invocation only if required (see Template talk:Post-nominals#Use of Module:Template_invocation); clean whitespace, variables
en>Pppery (Belatedly implementing edit request by SMcCandlish on talk page: no separators after empty parameters) |
en>Johnuniq (require Module:Template invocation only if required (see Template talk:Post-nominals#Use of Module:Template_invocation); clean whitespace, variables) |
||
Line 3: | Line 3: | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
local yesno = require('Module:Yesno') | local yesno = require('Module:Yesno') | ||
local | local p = {} | ||
p = {} | |||
function p.main(frame) | function p.main(frame) | ||
Line 27: | Line 26: | ||
local result = '' | local result = '' | ||
local addSeparator = false; | local addSeparator = false; | ||
for | for _, v in ipairs(variableVals) do | ||
v = mw.text.trim(v) | v = mw.text.trim(v) | ||
if #v > 0 or not yesno(args.skipBlanks) then | if #v > 0 or not yesno(args.skipBlanks) then | ||
if addSeparator then | if addSeparator then | ||
Line 43: | Line 42: | ||
result = result .. output | result = result .. output | ||
else | else | ||
local makeTemplate = require('Module:Template invocation').invocation | |||
result = result .. makeTemplate(template, targs) | result = result .. makeTemplate(template, targs) | ||
end | end | ||
Line 70: | Line 70: | ||
error("Both start/stop/by and numbered parameters specified") | error("Both start/stop/by and numbered parameters specified") | ||
end | end | ||
start = tonumber(args.start or 1) | local start = tonumber(args.start or 1) | ||
stop = tonumber(args.stop or 1) | local stop = tonumber(args.stop or 1) | ||
by = tonumber(args.by or 1) | local by = tonumber(args.by or 1) | ||
for i = start, stop, by do | for i = start, stop, by do | ||
variableVals [#variableVals + 1] = i | variableVals [#variableVals + 1] = i | ||
end | end | ||
Line 91: | Line 91: | ||
local nums = {} | local nums = {} | ||
local pattern = '^' .. prefix .. '([1-9]%d*)' .. suffix .. '$' | local pattern = '^' .. prefix .. '([1-9]%d*)' .. suffix .. '$' | ||
for k, | for k, _ in pairs(args) do | ||
local num = tostring(k):match(pattern) | local num = tostring(k):match(pattern) | ||
if num then | if num then |