Module:Ustring

From The League Wiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:Ustring/doc

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
})