diff options
| author | 2026-02-15 21:10:26 -0600 | |
|---|---|---|
| committer | 2026-02-15 21:10:26 -0600 | |
| commit | 529d8c9e4a20726b9158d277c100f738dd6b7873 (patch) | |
| tree | 835c1e4a5b84c9975cb02e3d4b35bc1ae0f6d2d5 | |
| parent | Allow garbage collection to be called inside the module entry. (diff) | |
Improve ability to load modules by full path.
Be explicit when we are including this functionality. Add a function
module/add-file-extension that can do this programatically.
| -rw-r--r-- | src/boot/boot.janet | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 3e103009..7296e9cc 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -2910,7 +2910,9 @@ 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`. + keyword name of a loader in `module/loaders`. The parameter `match-exact-path` + will allow users to import files with this extension directly with a relative + or absolute path. Returns the modified `module/paths`. ``` [ext loader] (def mp (dyn *module-paths* module/paths)) @@ -2925,6 +2927,17 @@ (array/insert mp sys-index [(string ":sys:/:all:" ext) loader check-is-dep]) (def curall-index (find-prefix ":cur:/:all:")) (array/insert mp curall-index [(string ":cur:/:all:" ext) loader check-relative]) + mp) + +(defn module/add-file-extension + ``` + Add paths to `module/paths` for a given file extension such that + the programmer can import a module by relative or absolute path. + Returns the modified `module/paths`. + ``` + [ext loader] + (assert (string/has-prefix? "." ext) "file extension must have . prefix") + (def mp (dyn *module-paths* module/paths)) (array/insert mp 0 [":all:" loader (fn :check-ext [x] (string/has-suffix? ext x))]) mp) @@ -2950,6 +2963,12 @@ (module/add-paths "/init.janet" :source) (module/add-paths ".janet" :source) (module/add-paths ".jimage" :image) +(module/add-file-extension ".janet" :source) +(module/add-file-extension ".jimage" :source) +# These obviously won't work on all platforms, but if a user explicitly +# tries to import them, we may as well try. +(module/add-file-extension ".so" :native) +(module/add-file-extension ".dll" :native) (array/insert module/paths 0 [(fn is-cached [path] (if (in (dyn *module-cache* module/cache) path) path)) :preload |
