Module:Ustring: Difference between revisions

Content deleted Content added
Undid revision 886758119 by Ans (talk) The thing is, though, that Module:Ustring is the only module on all of Wikipedia that calls Module:LuaCall, so no "common code" argument can be made with p.import, which is in any case out of scope of the module
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)
Line 1:
require('Module:No globals')
local p = {}
return setmetatable({}, {
 
__index = function(t, k)
for k, v in pairs(mw.ustring) do
p[k] = return function(frame)
local args = frame.args
for _, v in ipairs(args) do
args[_] = tonumber(v) or v:gsub("^\\", "", 1)
end
if args.tag then
local tag = {name = args.tag, content = mw.ustring[k](unpack(args)), 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
return frame:extensionTag(tagmw.ustring[k](unpack(args)))
end
return (mw.ustring[k](unpack(args)))
end
})
end
 
return p