Module:MultiRequire

require('Module:LibraryUtil') local deepCopy = require('Module:Table').deepCopy

local function formatError(e, module) if type(e) ~= 'string' then return nil end if e:match('not found') then return ('Module %q was not found'):format(module) elseif e:match('loop') then return ('Loop or previous error loading module %q'):format(module) elseif e:match('^Module:') then return ('Exception in loading module %q at line %s: %s'):format(module, e:match('^Module:%w+:(%d+)'), e:gsub('^Module:%w+:%d+:%s*', '')) end end

function multiRequire(...) local v = checkArgs({ { 'string', 'table' } }, ...) local tp = type(v) local ret = {} if tp == 'string' then for i, module in forEachArgs('string', ...) do 			local success, res = pcall(require, module) assertTrue(success, formatError(res, module), 2) table.insert(ret, res) end else for i, module in ipairs(v) do			local success, res = pcall(require, module) assertTrue(sucess, formatError(res, module), 2)

table.insert(ret, res) end end if tp == 'string' then return unpack(ret) else return ret end end

local function formatDataLoadError(e, module) if type(e) ~= 'string' then return nil end if e:match('unsupported') then return ('The data from module %q contains an unsupported data type %q'):format(module, e:match('unsupported data type [\"\'](.-)[\"\']')) elseif e:match('metatable') then return ('The data from module %q contains a table with a metatable'):format(module, e:match('unsupported data type [\"\'](.-)[\"\']')) elseif e:match('loop') then return ('Loop or previous error loading module %q'):format(module) end end

function loadDataMulti(...) local v = checkArgs({ { 'string', 'table' } }, ...) local tp = type(v) local ret = {} if tp == 'string' then for i, module in forEachArgs('string', ...) do 			local success, res = pcall(mw.loadData, module) assertTrue(success, formatDataLoadError(res, module), 2) table.insert(ret, res) end else for i, module in ipairs(v) do			local success, res = pcall(mw.loadData, module) assertTrue(sucess, formatDataLoadError(res, module), 2)

table.insert(ret, res) end end if tp == 'string' then return unpack(ret) else return ret end end

return { multiRequire=multiRequire, loadDataMulti=loadDataMulti }