Jump to content

Module:Ustring/sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by GKFX (talk | contribs) at 17:48, 7 October 2021 (Support string arguments without '\' prefix). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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 args.tag then
				return what(unpack(args))
			end
			local tagargs = {}
			for x, y in pairs(args) do
				if type(x) ~= 'number' and x ~= 'tag' then tagargs[x] = y end
			end
			return frame:extensionTag{name = args.tag, content = what(unpack(args)), args = tagargs}
		end
	end
})