Jump to content

Module:Ustring: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m Changed protection level for "Module:Ustring": High-risk Lua module: per request at WP:RFPP; used by TE protected Template:R from Unicode character ([Edit=Require template editor access] (indefinite))
Make it possible to pass strings like '0005' to new arguments s1, s2, ... without having leading zeroes stripped
Line 1: Line 1:
require('Module:No globals')
return setmetatable({}, {
return setmetatable({}, {
__index = function(t, k)
__index = function(t, k)
Line 7: Line 6:
end
end
return function(frame)
return function(frame)
local args = frame.args
local args = {}
local str_i = 1
for _, v in ipairs(args) do
while frame.args['s' .. str_i] do
args[_] = tonumber(v) or v:gsub("^\\", "", 1)
args[str_i] = frame.args['s' .. str_i]
str_i = str_i + 1
end
end
for i, v in ipairs(frame.args) do
if not args.tag then
args[i + str_i - 1] = tonumber(v) or v:gsub("^\\", "", 1)
return (what(unpack(args)))
end
if not frame.args.tag then
return what(unpack(args))
end
end
local tagargs = {}
local tagargs = {}
for x, y in pairs(args) do
for x, y in pairs(frame.args) do
if type(x) ~= 'number' and x ~= 'tag' then tagargs[x] = y end
if type(x) ~= 'number' and x ~= 'tag' then tagargs[x] = y end
end
end
return frame:extensionTag{name = args.tag, content = what(unpack(args)), args = tagargs}
return frame:extensionTag{name = frame.args.tag, content = what(unpack(args)), args = tagargs}
end
end
end
end

Revision as of 17:53, 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
				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
})