Module jls.lang.loader

This module contains helper functions to load Lua modules.

The loader module is fully compatible with the Lua require function.

Functions

tryRequire (name) Requires the specified Lua module.
requireList (names[, try]) Requires the specified Lua modules.
getRequired (name) Returns the specified Lua module if already loaded.
singleRequirer (name) Returns a funtion that will try to require the specified Lua module only once.
lazyFunction (providerFn) Builds a function by requiring its dependencies on first call.
requireOne (...) Requires one of the specified Lua modules.
requireByPath (path[, try]) Requires the Lua object specified by its path.
unload (name) Unloads the specified Lua module.
unloadAll (pattern) Unloads all the specified Lua modules.
load (name[, path[, try[, asRequire]]]) Loads a module using a specific path.


Functions

tryRequire (name)
Requires the specified Lua module.

Parameters:

  • name string the name of the module to load

Returns:

    the loaded module or nil if an error occured
requireList (names[, try])
Requires the specified Lua modules.

Parameters:

  • names table the list of the modules to load
  • try boolean true to return nil in place of raising an error (optional)

Returns:

    the loaded modules or nil values
getRequired (name)
Returns the specified Lua module if already loaded.

Parameters:

  • name string the name of the module to load

Returns:

    the already loaded module or nil if none
singleRequirer (name)
Returns a funtion that will try to require the specified Lua module only once.

Parameters:

  • name string the name of the module to load

Returns:

    funtion a function that will return the specified module or nil if an error occured
lazyFunction (providerFn)
Builds a function by requiring its dependencies on first call.

Parameters:

  • providerFn function A function which will be called only once with the loaded modules or nil values when modules are not found.

Returns:

    funtion the function returned by the providerFn parameter.
requireOne (...)
Requires one of the specified Lua modules. The order is: the first already loaded module then the first module whose name ends by an already loaded module. If no module could be loaded then an error is raised. If there is only one module then the base module shall be the same.

Parameters:

  • ... the ordered names of the module eligible to load

Returns:

    the loaded module

Usage:

    return require('jls.lang.loader').requireOne('jls.io.fs-luv', 'jls.io.fs-lfs')
requireByPath (path[, try])
Requires the Lua object specified by its path.

Parameters:

  • path string the pathname of the module to load
  • try boolean true to return nil in place of raising an error (optional)

Returns:

    the loaded module
unload (name)
Unloads the specified Lua module. The module is removed from the loaded modules and will be loaded again on a require. This is not the opposite of the require and bad things could happen.

Parameters:

  • name string the name of the module to unload
unloadAll (pattern)
Unloads all the specified Lua modules.

Parameters:

  • pattern string the pattern of the module names to unload

Usage:

    require('jls.lang.loader').unloadAll('^jls%.')
load (name[, path[, try[, asRequire]]])
Loads a module using a specific path.

Parameters:

  • name string the name of the module to load
  • path string the path of the module to load (optional)
  • try boolean true to return nil in place of raising an error (optional)
  • asRequire boolean true to be compatible with require by using package.loaded (optional)

Returns:

    the loaded module or nil if an error occured
generated by LDoc 1.4.6 Last updated 2022-01-22 16:32:56