hypixel skyblock
Lock
Page Protected from Editing
This page is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, it is subject to Page Protection.

This module provides two functions function that makes calling require() and mw.loadData() multiple easy.

Dependent Module

Loading the module

To load this module and make its method available for use, Add this line of code to the start of your module:

require('Module:MultiRequire')

The described functions below will be able to be used as they are saved as global variables in the module this module was loaded in.

Alternatively, you can use this module using the code below by using Module:LoadLib.

local loadLib = require('Module:LoadLib')

_G = loadLib(_G, {
    { 'Module:MultiRequire' },
    -- Place any other modules to load in here...
})

Depending on the settings you used in loadLib(), the methods of this module may be available under their respective variables in the module this module was loaded in.

Return Values

This module returns two functions:

  • multiRequire() - Allows of loading of multiple modules at once.
  • loadDataMulti() - Exactly the same as multiRequire(), but uses mw.loadData() instead of require().

multiRequire

multiRequire(<module 1/modules>(any)<module 2>(any)...(any)<module N>(any))
Returns any values returned by require() are returned. If the input is a table, it returns a table of the loaded modules. If variable length arguments are used, it returns the unpacked values. It will throw an error if the module is not found or if there was an error in loading one of the requested modules.

Examples

  • multiRequire('Module:String')<methods from Module:String>
  • multiRequire{ 'Module:String', 'Module:Table' }{ <methods from Module:String>, <methods from Module:Table> }

loadDataMulti

multiRequire(<module 1/modules>(any)<module 2>(any)...(any)<module N>(any))
Works exactly the same as multiRequire(), but uses mw.loadData() instead internally.

Examples

  • multiRequire('Module:Pet/Data')<data from Module:Pet/Data>
  • multiRequire{ 'Module:UIText/Data', 'Module:Pet/Data' }{ <data from Module:UIText/Data>, <data from Module:Pet/Data> }

Submodules

No submodules found for this page. Try purging the page or viewing all subpages.


See Also

Hypixel SkyBlock Wiki Standard Lua Libraries (hsw/stdll) v · d · e
Type Libraries
Module Loading Utilities
  • Module:Loader (Current standard for normal/lazy loading)
  • Module:LoadLib (Auto loads some modules; customizable method loading)
  • Module:MultiRequire (Also pushes all exports to _G)
General Utilities
Meta Modules
Object-oriented
Caching
Module:MultiRequire/doc

Module Code

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