模块:CallAssert:修订间差异
跳到导航
跳到搜索
ahp>Xiplus-abot 小 (已保护“Module:CallAssert”:高風險模板:11826引用<!-- 機器人3 -->([编辑=仅允许模板编辑员](无限期)[移动=仅允许模板编辑员](无限期))) |
小 (导入1个版本) |
(没有差异)
|
2023年11月7日 (二) 17:24的最新版本
可在模块:CallAssert/doc创建此模块的帮助文档
脚本错误:Lua错误:无法创建进程:proc_open(/dev/null): failed to open stream: Operation not permitted
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