Content deleted Content added
copy from Module:ForLoop |
test |
||
(17 intermediate revisions by 4 users not shown) | |||
Line 3:
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local p = {}
function p.templatemain(frame)
return p.main(frame:newChild{title = "Template:For_loop"})
end
function p.main(frame)
Line 15 ⟶ 19:
function p._main(args)
local template = args['call'] or 'void'
local calltemplates = yesno(args.substall or "", true) or not mw.isSubsting()
local variableParam = args.pv
variableParam = tonumber(variableParam) or variableParam or 1 -- fix for positional parameters
Line 25 ⟶ 30:
local result = ''
local addSeparator = false;
for
v = mw.text.trim(v)
if #v > 0 or not yesno(args.skipBlanks) then
if addSeparator then
Line 34 ⟶ 39:
local targs = constantArgs
targs[variableParam] = variableValPrefix .. v .. variableValPostfix
if calltemplates then
local
result = result .. expandedTemplate▼
if #mw.text.trim(output) == 0 then
addSeparator = false
end
else
local makeTemplate = require('Module:Template invocation').invocation
result = result .. makeTemplate(template, targs)
end
end
end
Line 57 ⟶ 70:
function p.getVariableVals(args)
local variableVals = {}
if args.start or args.stop or args.by then
for i, v in ipairs(args) do▼
if
error("Both start/stop/by and numbered parameters specified")
variableVals[i - 1] = v▼
end
local start = tonumber(args.start or 1)
local stop = tonumber(args.stop or 1)
local by = tonumber(args.by or 1)
for i = start, stop, by do
variableVals [#variableVals + 1] = i
end
else
if i ~= 1 then
▲ variableVals[i - 1] = v
end
end
end
Line 70 ⟶ 95:
local nums = {}
local pattern = '^' .. prefix .. '([1-9]%d*)' .. suffix .. '$'
for k,
local num = tostring(k):match(pattern)
if num then
|