跳转到内容

模組:Loop

本页使用了标题或全文手工转换
维基百科,自由的百科全书

这是本页的一个历史版本,由SunAfterRain留言 | 贡献2024年1月23日 (二) 05:58 (SunAfterRain移動頁面Module:ForIoopModule:Loop:​拼寫錯誤)编辑。这可能和当前版本存在着巨大的差异。

local p = {}
local yesno
local mTemplateParameters

function p.main(frame)
	local args = frame.args
	local loopStart = tonumber(args['start']) or 0
	local loopEnd = tonumber(args['end']) or 0
	local loopContent = args.content
	if loopStart == loopEnd or not loopContent then
		return ''
	end
	local loopRange = tonumber(args['range']) or 1
	if loopStart > loopEnd or loopRange < 0 then
		error('Only increment syntax allowed.')
	end
	if not yesno then
		yesno = require('Module:Yesno')
	end
	if yesno(args.delnowiki) then
		loopContent = mw.text.unstripNoWiki(loopContent)
	end
	if yesno(args.delmsgnw) then
		loopContent = mw.text.decode(loopContent)
	end
	if yesno(args.usingConditionalExpressions) then
		if not mTemplateParameters then
			mTemplateParameters = require('Module:TemplateParameters')
		end
		loopContent = mTemplateParameters._get_escape(loopContent)
	end
	local i = loopStart
	local output = ''
	while true do
		output = output .. loopContent:gsub('{{{1}}}', tostring(i))
		i = i + loopRange
		if i > loopEnd then
			break
		end
	end
	return mw.getCurrentFrame():preprocess(output)
end

return p