Jump to content

Module:Ustring: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Can you not reinvent the wheel?
minor optimizations by avoiding extraneous multi-table references and returning most common cases first
Line 11: Line 11:
args[_] = tonumber(v) or v:gsub("^\\", "", 1)
args[_] = tonumber(v) or v:gsub("^\\", "", 1)
end
end
if args.tag then
if not args.tag then
local tag = {name = args.tag, content = mw.ustring[k](unpack(args)), args = {}}
return (what(unpack(args)))
for x, y in pairs(args) do
if type(x) ~= 'number' and x ~= 'tag' then tag.args[x] = y end
end
return frame:extensionTag(tag)
end
end
local tagargs = {}
return (mw.ustring[k](unpack(args)))
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
end
end

Revision as of 23:58, 30 April 2020

require('Module:No globals')
return setmetatable({}, {
	__index = function(t, k)
		local what = mw.ustring[k]
		if type(what) ~= "function" then
			return what
		end
		return function(frame)
			local args = frame.args
			for _, v in ipairs(args) do
				args[_] = 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
})