Module dslib:mmodules

A module for registering new modules.

As a convention, module names begin with "<modname>:".

Furthermore, it is suggested to use "<modname>:internal.<...>" for mod-internal stuff, and "<modname>:api" if the mod just wants to expose its api as a whole.

Functions

mrequire (name) An alias for dslib.mrequire.
try_mrequire (name) Tries to load a module.
is_loaded (name) Checks if a module is loaded.
is_loading (name) Checks if a module is currently loading.
exists (name) Checks if a module was registered.
add_module_loader_uplooker (func) Adds a function to look for module loaders.
add_module_by_loader (name, loader) Adds a module with a loader function for it.
add_module_by_value (name, value) Adds a value as a module.
add_module_by_string (name, code_str) Adds a module via its source code.
add_module_by_file (name, path) Adds a module via its file.


Functions

mrequire (name) line 94
An alias for dslib.mrequire.

Parameters:

try_mrequire (name) line 110
Tries to load a module.

Use this instead of pcalling mrequire.

Parameters:

Returns:

  1. The module's retval, or nil or false on failure.
  2. nil on success, otherwise the error message (a string).
is_loaded (name) line 117
Checks if a module is loaded.

Parameters:

  • name string The name of the module.

Returns:

    bool Whether module name was loaded.
is_loading (name) line 126
Checks if a module is currently loading.

dslib.mrequire(name) was called, but didn't return yet.

Parameters:

  • name string The name of the module.

Returns:

    bool Whether module name is currently loading.
exists (name) line 133
Checks if a module was registered.

Parameters:

  • name string The name of the module.

Returns:

    bool Whether module name is registered.
add_module_loader_uplooker (func) line 159
Adds a function to look for module loaders.

func(module_name) must either return nothing (=> no loader found) or return a loader function.

Semantics of a loader function l:

  • retval, errmsg = l(module_name) will be used by try_mrequire and mrequire to load the module.
  • If retval is nil, the loading fails, but l will be called again on another try_mrequire or mrequire call.
  • If retval is false, the loading fails, and no more attempts for loading the respective module will be made.
  • If retval is any other value, the loading succeeds and retval is the module's retval.
  • Iff the loading fails, errmsg should be a string indicating the error.

You will very likely not need this. Try mmodules.add_module_by_loader first.

Parameters:

  • func function The uplooker function.
add_module_by_loader (name, loader) line 177
Adds a module with a loader function for it.

loader(name) will be called to load the module. See add_module_loader_uplooker for details on loader functions.

Parameters:

  • name string The name of the module.
  • loader function Will be called to load the module.
add_module_by_value (name, value) line 187
Adds a value as a module.

When loading, value will be returned.

Parameters:

  • name string The name of the module.
  • value The return value of the module. Must not be nil or false.
add_module_by_string (name, code_str) line 200
Adds a module via its source code.

When loading, the code will be loaded and used as loader function. See add_module_loader_uplooker for details on loader functions.

Parameters:

  • name string The name of the module.
  • code_str string The code.
add_module_by_file (name, path) line 213
Adds a module via its file.

When loading, the code in the file will be loaded and used as loader function. See add_module_loader_uplooker for details on loader functions.

Parameters:

  • name string The name of the module.
  • path string The path of the file.
generated by LDoc 1.4.6 Last updated 2023-04-02 20:41:54