Module:LoadLib/doc

This module is used to ease the loading of other modules. It does this by utilizing the global variable table, which allows for more flexibility in variables. It will also automatically load several modules.

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

Syntax

 * - The parameter is the global table. This must be the specific variable _G or the function will fail.
 * - The collection of modules to load. Each key name in this table represents the variable to save the loaded module under. each key may be a table, with the table containing options for the loader for that specific module. See the section below for more details.

Use
This module provides a singe function to load other modules.

This function has options that emulate normal lua code. .

Note that in these examples, sometimes the named table index is not omitted, which prevents the entire module from being loaded. If the table index is omitted, the loader will load the module under the index name.

Variable setting
You can also add the field setVars to true to make the loader set each method in the module as a variable in the loaded module.

Example
Once this code is added to the module, any methods described in Module:ModuleName will be available as variables in the loaded modules with the variable name being the respective method in Module:ModuleName.

Paths
This module also provides basic relative paths and substitution variables. Any relative paths are substituted to absolute paths. These basic relative paths are the following:
 * Note in these examples that the current page name is Module:String/Data.
 * A / at the start of the module name denotes a subpage of the parent (not the root) module.
 * Example: /Test → Module:String/Test
 * Example: /Foo/Test → Module:String/Foo/Test
 * A ./ at the start of the module name denotes a subpage of the root module.
 * Example: ./Test → Module:String/Test
 * Example: ./Foo/Test → Module:String/Foo/Test
 * A ../ at the start of the module name denotes a subpage of the current module.
 * Example: ../Test → Module:String/Data/Test
 * Example: ../Foo/Test → Module:String/Data/Foo/Test

Autoloads
This module automatically loads a preset list of commonly used modules. These modules may be found in. These may be disabled entirely using options.doAutoLoads or some modules may be filtered using the options.skip parameter.

Variables
You can also use variables (denoted by ${ }) in the paths. These variables are substituted with the contents they repersent. The list of built-in variables is as follows:
 * ${root} denotes the root page name.
 * ${page} denotes the current page name.
 * ${subpage} denotes the current subpage name.
 * ${base} and ${parent} denotes the base (not root) page name.
 * ${fullpage} denotes the current page name (with the namespace prefix).

Custom variables can be created by adding a table in the subst or substVars field in the parameter. The table index in the table for variables represents the variable name, and the table value its contents. A custom variable may be called with the following syntax: ${var: }

Example
The example variable here is set to Foo and it's name is foo. The page name in the example is Module:Test
 * Module:Test/${page}/${var:foo} → Module:Test/Test/Foo
 * Module:${var:foo}/${page} → Module:Foo/Test

Code Example
The current page name in this example is Module:String. Note that the current path "Module:Test/${page}/${var:foo}" will get subsituted to.

Note the module will throw an error if a custom variable does not exist or there is no substitution table to draw from. All methods from Module:Test/String/Foo will now be availible under the test object in the module the function was used.

Options
The following consists of different options for the loader to load the module. Note that you can group each of these options together in one call.

Option 1
This option replicates a standard call. See the section below for the Replicated code.

Once this line of code is added to your module, the module and its methods are available under the table index name. In this case, all methods of Module:ModuleName are available under the variable moduleName.

Option 2
This option replicates a call and getting a single field from the module and setting that field name as the variable to be used. See the section below for the emulated code.

Once this code is added, the method from Module:ModuleName is is available under the foo variable.

Option 3
This option replicates a call and getting a single field from the module and setting that field name as a different variable from the method name. See the section below for the emulated code.

Once this code is added, the method from Module:ModuleName is is available under the bar variable.

Option 4
This option replicates a call and getting multiple fields from the module and setting that field name as the variable to be used. See the section below for the emulated code. {{darkCodeBox|lang=lua|t= _G = loadLib(_G, {   { 'Module:ModuleName', values={ 'foo', 'bar', 'baz' }    -- Any other modules to load go here }) }} Once this code is added, the methods, , and from Module:ModuleName is is available under the foo, bar, and baz variables respectively.

Option 5
This option replicates a call and getting multiple fields from the module and setting that field name as a different variable from the respective method name. See the section below for the emulated code. {{darkCodeBox|lang=lua|t= _G = loadLib(_G, {   { 'Module:ModuleName', values={ qux='foo', lorem='bar', ipisum='baz' }    -- Any other modules to load go here }) }} Once this code is added, the methods, , and from Module:ModuleName is is available under the qux, lorem, and ipisum variables respectively.
 * Note that this method may be mixed with the method above.