Jump to content

Module:Ustring and Module:Ustring/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
m Changed protection settings for "Module:Ustring": Used by fully protected Template:Str rightc -> Template:New page DYM -> Template:No article text (-> WP:CASC) ([Edit=Require administrator access] (indefinite))
 
use require('strict') instead of require('Module:No globals')
 
Line 8: Line 8:
return function(frame)
return function(frame)
local fargs = frame.args
local fargs = frame.args
local fargsused = { tag = true }
local fargsused = { tag = true, onerror = true }
local args = {}
local args = {}
local str_i = 1
local str_i = 1
Line 19: Line 19:
fargsused[i] = true
fargsused[i] = true
args[i + str_i - 1] = tonumber(v) or v:gsub("^\\", "", 1)
args[i + str_i - 1] = tonumber(v) or v:gsub("^\\", "", 1)
end
local result = nil
if fargs.onerror then
local success
success, result = pcall(what, unpack(args))
if not success then
return fargs.onerror
end
else
result = what(unpack(args))
end
end
if not fargs.tag then
if not fargs.tag then
return result
return (what(unpack(args))) -- Outside parens truncate to first result avoiding tail call
end
end
local tagargs = {}
local tagargs = {}
Line 27: Line 37:
if not fargsused[x] then tagargs[x] = y end
if not fargsused[x] then tagargs[x] = y end
end
end
return frame:extensionTag{name = fargs.tag, content = what(unpack(args)), args = tagargs}
return frame:extensionTag{name = fargs.tag, content = result, args = tagargs}
end
end
end
end