Module luarocks.require
Application interface with LuaRocks. Load this module to LuaRocks-enable an application: this overrides the require() function, making it able to load modules installed as rocks.
Functions
add_context (name, version, manifest) | Process the dependencies of a package to determine its dependency chain for loading modules. |
get_rock_from_module (module, constraints) | Inform which rock LuaRocks would use if require() is called with the given arguments. |
plain_require_on (module, name, version, rocks_dir, ...) | Call the vanilla require() function using specially constructed package paths so that it finds exactly the version we want it to find. |
require (module, ..., constraints) | Function that overloads require(), adding LuaRocks support. |
set_context (name, version) | Specify a dependency chain for LuaRocks. |
sort_versions (a, b) | Internal sorting function. |
Functions
- add_context (name, version, manifest)
-
Process the dependencies of a package to determine its dependency chain for loading modules.
Parameters
- name:
- version:
- manifest:
- get_rock_from_module (module, constraints)
-
Inform which rock LuaRocks would use if require() is called with the given arguments.
Parameters
- module: string: The module name, like in plain require().
- constraints: string or nil: An optional comma-separated list of version constraints.
Return value:
(string, string) or nil: Rock name and version if the requested module can be supplied by LuaRocks, or nil if it can't. - plain_require_on (module, name, version, rocks_dir, ...)
-
Call the vanilla require() function using specially constructed package paths so that it finds exactly the version we want it to find.
Parameters
- module: string: The module name, in require() notation.
- name: string: The rock name.
- version: string: The rock version.
- rocks_dir:
- ...:
Return value:
The result returned by require(). - require (module, ..., constraints)
-
Function that overloads require(), adding LuaRocks support. This function wraps around Lua's standard require() call, allowing it to find modules installed by LuaRocks. A module is searched in installed rocks that match the current LuaRocks context. If module is not part of the context, or if a context has not yet been set, the module in the package with the highest version is used. If a module is not available in any installed rock, plain require() is called, using the original package.path and package.cpath lookup locations. Additionally, version constraints for the matching rock may be given as a second parameter. If version constraints could not be fulfilled, this equates to the rock not being available: as such, plain require() with the default paths is called as a fallback.
Parameters
- module: string: The module name, like in plain require().
- ...:
- constraints: string or nil: An optional comma-separated list of version constraints.
Return value:
table: The module table (typically), like in plain require(). See require() in the Lua reference manual for details. - set_context (name, version)
-
Specify a dependency chain for LuaRocks. In the presence of multiple versions of packages, it is necessary to, at some point, indicate which dependency chain we're following. set_context does this by allowing one to pick a package to be the root of this dependency chain. Once a dependency chain is picked it's easy to know which modules to load ("I want to use *this* version of A, which requires *that* version of B, which requires etc etc etc").
Parameters
- name: string: The package name of an installed rock.
- version: string or nil: Optionally, a version number When a version is not given, it picks the highest version installed.
Return value:
boolean: true if succeeded, false otherwise. - sort_versions (a, b)
-
Internal sorting function.
Parameters
- a: table: A provider table.
- b: table: Another provider table.
Return value:
boolean: True if the version of a is greater than that of b.