-
JANET_PATH
<->:syspath
: https://github.com/janet-lang/janet/blob/daa37c22f5c7b777b4fb5af620c791dc84bea1a9/src/boot/boot.janet#L2642 -
:syspath
<->module/expand-path
(janet_core_expand_path
): https://github.com/janet-lang/janet/blob/daa37c22f5c7b777b4fb5af620c791dc84bea1a9/src/core/corelib.c#L151 -
module/expand-path
<->module/find
: https://github.com/janet-lang/janet/blob/daa37c22f5c7b777b4fb5af620c791dc84bea1a9/src/boot/boot.janet#L2710 -
module/find
<->require-1
: https://github.com/janet-lang/janet/blob/daa37c22f5c7b777b4fb5af620c791dc84bea1a9/src/boot/boot.janet#L2820 -
require-1
<->import*
: https://github.com/janet-lang/janet/blob/daa37c22f5c7b777b4fb5af620c791dc84bea1a9/src/boot/boot.janet#L2860
@[(<function is-cached> :preload <function check-is-dep>)
(":cur:/:all:.jimage" :image <function check-relative>)
(":cur:/:all:.janet" :source <function check-relative>)
(":cur:/:all:/init.janet" :source <function check-relative>)
(":cur:/:all::native:" :native <function check-relative>)
(":sys:/:all:.jimage" :image <function check-is-dep>)
(":sys:/:all:.janet" :source <function check-is-dep>)
(":sys:/:all:/init.janet" :source <function check-is-dep>)
(":sys:/:all::native:" :native <function check-is-dep>)
(".:all:.jimage" :image <function check-project-relative>)
(".:all:.janet" :source <function check-project-relative>)
(".:all:/init.janet" :source <function check-project-relative>)
(".:all::native:" :native <function check-project-relative>)]
Some examples:
repl:1:> (module/expand-path "hello" ":cur:/:all:.janet")
@"hello.janet"
repl:2:> (module/expand-path "hello" ":sys:/:all:.janet")
@"/home/user/.local/lib/janet/hello.janet"
repl:3:> (module/expand-path "hello" ":sys:/:dir:.janet")
@"/home/user/.local/lib/janet/.janet"
repl:4:> (module/expand-path "hello" ":sys:/:name:.janet")
@"/home/user/.local/lib/janet/hello.janet"
repl:5:> (module/expand-path "hello" "./:name:.janet")
@"hello.janet"
repl:6:> (module/expand-path "hello" "./:name::native:")
@"hello.so"
See janet_core_expand_path in corelib.c for more details.
The check-*
functions:
(defn- check-relative [x]
(if (string/has-prefix? "." x)
x))
(defn- check-is-dep [x]
(unless (or (string/has-prefix? "/" x)
(string/has-prefix? "." x))
x))
(defn- check-project-relative [x]
(if (string/has-prefix? "/" x)
x))
(def module/loaders
`A table of loading method names to loading functions.
This table lets require and import load many different kinds
of files as modules.`
@{:native (fn native-loader [path &] (native path (make-env)))
:source (fn source-loader [path args]
(put module/loading path true)
(defer (put module/loading path nil)
(dofile path ;args)))
:preload (fn preload-loader [path & args]
(when-let [m (in module/cache path)]
(if (function? m)
(set (module/cache path) (m path ;args))
m)))
:image (fn image-loader [path &] (load-image (slurp path)))})