Module:MultiRequire

require('Module:LibraryUtil')

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 res = require(module) table.insert(ret, res) end else for i, module in ipairs(v) do			local res = require(module)

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

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 res = mw.loadData(module) table.insert(ret, res) end else for i, module in ipairs(v) do			local res = mw.loadData(module)

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

return { multiRequire=multiRequire, loadDataMulti=loadDataMulti, formatDataLoadError=formatDataLoadError, formatError=formatError, }