Module:CallAssert:修订间差异
来自大天使虫洞百科
更多操作
zh>Xiplus-abot 小 已更改“Module:CallAssert”的保护设置:高風險模板:115539引用<!-- 機器人3 -->([编辑=仅允许管理员](无限期)[移动=仅允许管理员](无限期)) |
小 导入1个版本 |
||
(没有差异)
| |||
2024年10月14日 (一) 07:12的最新版本
| File:Icons8 flat synchronize.svg | 本模块已与Module:Interwiki第71行Lua错误:attempt to index field 'wikibase' (a nil value)保持全域手动同步。 请注意,若您修改本地的模块,将可能影响同步。 |
local function pack(...)
return {...}, select('#', ...)
end
local function mapArray(func, array, count)
local result = {}
for i = 1, count or #array do
result[i] = func(array[i])
end
return result
end
local function quote(value)
if type(value) == 'string' then
return (string.gsub(string.format('%q', value), '\\\n', '\\n')) -- Outer parentheses remove second value returned by gsub
end
local str = tostring(value)
if type(value) == 'table' and str ~= 'table' then
return '{' .. str .. '}'
end
return str
end
local function callAssert(func, funcName, ...)
local result, resultCount = pack(func(...))
if not result[1] then
local args, argsCount = pack(...)
args = mapArray(quote, args, argsCount)
local message = mw.ustring.format(
'%s(%s) failed',
funcName,
table.concat(args, ', ')
)
error(message, 2)
end
return unpack(result, 1, resultCount)
end
return callAssert