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:
- name See dslib.mrequire.
- try_mrequire (name) line 110
-
Tries to load a module.
Use this instead of pcalling mrequire.
Parameters:
- name See mrequire.
Returns:
-
The module's retval, or
nilorfalseon failure. -
nilon 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
namewas 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
nameis currently loading. - exists (name) line 133
-
Checks if a module was registered.
Parameters:
- name string The name of the module.
Returns:
-
bool
Whether module
nameis 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
retvalisnil, the loading fails, butlwill be called again on another try_mrequire or mrequire call. - If
retvalisfalse, the loading fails, and no more attempts for loading the respective module will be made. - If
retvalis any other value, the loading succeeds andretvalis the module's retval. - Iff the loading fails,
errmsgshould be a string indicating the error.
You will very likely not need this. Try
mmodules.add_module_by_loaderfirst.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,
valuewill be returned.Parameters:
- name string The name of the module.
- value
The return value of the module. Must not be
nilorfalse.
- 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:
- 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: