Module:Ustring: Difference between revisions

Content deleted Content added
Invert: dynamically import any function from mw.ustring upon demand instead of traversing and importing all functions from mw.ustring at every invocation since only one can actually be called at a time; even Module:LuaCall does this better passing just the single name to access instead of attempting to traverse and export an entire namespace like _G (which is clearly infeasible)
maintain error messages
Line 1:
require('Module:No globals')
return setmetatable({}, {
__index = function(t, kf)
return function(frame)
if nil == mw.ustring[f] then
return '<strong class="error">'..mw.message.new('scribunto-common-nosuchfunction', '', f):plain()..'</strong>'
end
if 'function' ~= type(mw.ustring[f]) then
return '<strong class="error">'..mw.message.new('scribunto-common-notafunction', '', f):plain()..'</strong>'
end
local args = frame.args
for _i, v in ipairs(args) do
args[_i] = tonumber(v) or v:gsub("^\\", "", 1)
end
if args.tag then
local tagargs = {}
local tag = {name = args.tag, content = mw.ustring[k](unpack(args)), args = {}}
for xk, yv in pairs(args) do
if 'number' ~= type(xk) ~=and 'numbertag' and x ~= 'tag'k then tag.argstagargs[xk] = yv end
end
return frame:extensionTag({name = args.tag, content = mw.ustring[f](unpack(args)), args = tagargs}
end
return (mw.ustring[kf](unpack(args)))
end
end