Module:Ustring/sandbox: Difference between revisions

Content deleted Content added
sync
use require('strict') instead of require('Module:No globals')
 
(3 intermediate revisions by 2 users not shown)
Line 1:
require('strict')
return setmetatable({}, {
__index = function(t, k)
Line 6 ⟶ 7:
end
return function(frame)
iflocal notfargs = frame.args.tag then
local fargsused = { tag = true, onerror = true }
local args = {}
local str_i = 1
while frame.argsfargs['s' .. str_i] do
args[str_i] = frame.argsfargsused['s' .. str_i] = true
args[str_i] = fargs['s' .. str_i]
str_i = str_i + 1
end
for i, v in ipairs(frame.argsfargs) do
fargsused[i] = true
args[i + str_i - 1] = tonumber(v) or v:gsub("^\\", "", 1)
end
local result = nil
if not frame.args.tag then
if fargs.onerror then
-- These brackets are important! Without them gsub will return multiple arguments.
local success
return (what(unpack(args)))
success, result = pcall(what, unpack(args))
if not success then
return fargs.onerror
end
else
returnresult = (what(unpack(args)))
end
if not fargs.tag then
return result
end
local tagargs = {}
for x, y in pairs(frame.argsfargs) do
if type(x) ~= 'number' andnot fargsused[x ~= 'tag'] then tagargs[x] = y end
end
return frame:extensionTag{name = frame.argsfargs.tag, content = what(unpack(args))result, args = tagargs}
end
end