Janet 1.17.1-e1c4fc2 Documentation
(Other Versions: 1.16.1 1.15.0 1.13.1 1.12.2 1.11.1 1.10.1 1.9.1 1.8.1 1.7.0 1.6.0 1.5.1 1.5.0 1.4.0 1.3.1 )

Module Module


module/add-paths module/cache module/expand-path module/find module/loaders module/loading module/paths

module/add-paths function source
(module/add-paths ext loader)

Add paths to `module/paths` for a given loader such that
the generated paths behave like other module types, including
relative imports and syspath imports. `ext` is the file extension
to associate with this module type, including the dot. `loader` is the
keyword name of a loader in `module/loaders`. Returns the modified `module/paths`.
Community Examples

module/cache table source
Table mapping loaded module identifiers to their environments.
Community Examples

module/expand-path cfunction source
(module/expand-path path template)

Expands a path template as found in `module/paths` for `module/find`. This takes in a path (the argument to require) and a template string, to expand the path to a path that can be used for importing files. The replacements are as follows:

* :all: -- the value of path verbatim

* :cur: -- the current file, or (dyn :current-file)

* :dir: -- the directory containing the current file

* :name: -- the name component of path, with extension if given

* :native: -- the extension used to load natives, .so or .dll

* :sys: -- the system path, or (dyn :syspath)
Community Examples

module/find function source
(module/find path)

Try to match a module or path name from the patterns in module/paths.
Returns a tuple (fullpath kind) where the kind is one of :source, :native,
or :image if the module is found, otherwise a tuple with nil followed by
an error message.
Community Examples

module/loaders table source
A table of loading method names to loading functions.
This table lets require and import load many different kinds
of files as modules.
Community Examples

module/loading table source
Table mapping currently loading modules to true. Used to prevent
circular dependencies.
Community Examples

module/paths array source
The list of paths to look for modules, templated for module/expand-path.
Each element is a two-element tuple, containing the path
template and a keyword :source, :native, or :image indicating how
require should load files found at these paths.

A tuple can also
contain a third element, specifying a filter that prevents module/find
from searching that path template if the filter doesn't match the input
path. The filter can be a string or a predicate function, and
is often a file extension, including the period.
Community Examples