Jump to content

Module:Reply to/sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Ahecht (talk | contribs) at 15:08, 7 April 2016 (Create module framework). 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 = {}

function p.reply( frame )
	-- Get the args table and work out the maximum arg key.
	local origArgs = frame:getParent().args
	local args = {}
	local maxArg = 0
	for k, v in pairs(origArgs) do
		if type(k) == 'number' and k > maxArg then
			maxArg = k
		end
		v = v:match('^%s*(.-)%s*$') -- Trim whitespace
		if v ~= '' then
			args[k] = v
		end
	end

	local maxNames = tonumber(frame.args.max) or 20
	if maxArg >= maxNames then
		return "{{error|Too many names specified. See [[:Template:Reply to]] for help.}}"
	else
		local outStr = "<span class='template-ping'>"..(frame:getParent().args.prefix or "@")
		for i = 1, maxArg do
			outStr = outStr.." "..i
		end
		return outStr
	end
end

return p