Module:MultiRequire

require('Module:LibraryUtil') local multiRequire = {}

function multiRequire.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.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 multiRequire.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 multiRequire.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

for k, v in pairs(multiRequire) do	_G[k] = v end

return multiRequire