Jump to content

Module:Ustring: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Make it possible to pass strings like '0005' to new arguments s1, s2, ... without having leading zeroes stripped
Re-add brackets around multival.
Line 16: Line 16:
end
end
if not frame.args.tag then
if not frame.args.tag then
-- These brackets are important! Without them gsub will return multiple arguments.
return what(unpack(args))
return (what(unpack(args)))
end
end
local tagargs = {}
local tagargs = {}

Revision as of 20:24, 7 October 2021

return setmetatable({}, {
	__index = function(t, k)
		local what = mw.ustring[k]
		if type(what) ~= "function" then
			return what
		end
		return function(frame)
			local args = {}
			local str_i = 1
			while frame.args['s' .. str_i] do
				args[str_i] = frame.args['s' .. str_i]
				str_i = str_i + 1
			end
			for i, v in ipairs(frame.args) do
				args[i + str_i - 1] = tonumber(v) or v:gsub("^\\", "", 1)
			end
			if not frame.args.tag then
				-- These brackets are important! Without them gsub will return multiple arguments.
				return (what(unpack(args)))
			end
			local tagargs = {}
			for x, y in pairs(frame.args) do
				if type(x) ~= 'number' and x ~= 'tag' then tagargs[x] = y end
			end
			return frame:extensionTag{name = frame.args.tag, content = what(unpack(args)), args = tagargs}
		end
	end
})