mirror of
https://github.com/janet-lang/janet
synced 2024-11-24 17:27:18 +00:00
Add :preload loader.
This commit is contained in:
parent
0f16f21677
commit
cd09b696b5
@ -2,6 +2,7 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## Unreleased - ???
|
||||
- Adds a :preload loader which allows one to manually put things into `module/cache`.
|
||||
- Add `buffer/push` function.
|
||||
- Backtick delimited strings and buffers are now reindented based on the column of the
|
||||
opening delimiter. WHitespace in columns to the left of the starting column is ignored unless
|
||||
|
@ -2560,6 +2560,10 @@
|
||||
(setdyn :syspath (boot/opts "JANET_PATH"))
|
||||
(setdyn :headerpath (boot/opts "JANET_HEADERPATH"))
|
||||
|
||||
(def module/cache
|
||||
"Table mapping loaded module identifiers to their environments."
|
||||
@{})
|
||||
|
||||
(defn module/add-paths
|
||||
```
|
||||
Add paths to module/paths for a given loader such that
|
||||
@ -2584,6 +2588,7 @@
|
||||
(module/add-paths "/init.janet" :source)
|
||||
(module/add-paths ".janet" :source)
|
||||
(module/add-paths ".jimage" :image)
|
||||
(array/insert module/paths 0 [(fn is-cached [path] (if (in module/cache path) path)) :preload])
|
||||
|
||||
# Version of fexists that works even with a reduced OS
|
||||
(defn fexists
|
||||
@ -2638,10 +2643,6 @@
|
||||
(undef check-.)
|
||||
(undef not-check-.)
|
||||
|
||||
(def module/cache
|
||||
"Table mapping loaded module identifiers to their environments."
|
||||
@{})
|
||||
|
||||
(def module/loading
|
||||
`Table mapping currently loading modules to true. Used to prevent
|
||||
circular dependencies.`
|
||||
@ -2706,6 +2707,11 @@
|
||||
(def newenv (dofile path ;args))
|
||||
(put module/loading path nil)
|
||||
newenv)
|
||||
:preload (fn [path & args]
|
||||
(when-let [m (in module/cache path)]
|
||||
(if (function? m)
|
||||
(set (module/cache path) (m path ;args))
|
||||
m)))
|
||||
:image (fn [path &] (load-image (slurp path)))})
|
||||
|
||||
(defn require-1
|
||||
|
Loading…
Reference in New Issue
Block a user