Module jls.lang.loader

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.
lazyMethod (mod, name, providerFn[, ...]) Adds a method 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.
load (name[, path[, try[, asRequire]]]) Loads a module using a specific path.
loadResource (name[, try]) Loads a resource.


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. You could pass the module names as arguments with the optional try mode as first argument.

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
lazyMethod (mod, name, providerFn[, ...])
Adds a method by requiring its dependencies on first call. Lazy method allows cycling dependencies between modules. The module method will be replaced on the first call, caching the boot method works but is not recommended.

Parameters:

  • mod table the module owning the method
  • name string the method name
  • providerFn function A function which will be called only once with the loaded modules or nil values when modules are not found
  • ... a list of module names to require and pass to the provider function (optional)

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:

  • ... string 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. If the full path cannot be required then each part of the path, separated by a dot '.', is required and the remaining part of the path are accessed in the module table.

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
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, could be package.path (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
loadResource (name[, try])
Loads a resource. A resource is data accessible in the Lua path or in the table package.resource. If no resource is found, or if there is any error loading the resource, then an error is raised. If package.resource[name] returns a function, then it is called to get the resource with the name as parameter.

Parameters:

  • name string the name of the resource to load using slash as separator, for example "a/b.json"
  • try boolean true to return nil in place of raising an error (optional)

Returns:

    string the resource
generated by LDoc 1.4.6