Last active
December 7, 2020 02:09
-
-
Save bakpakin/b4a87d95055142fa84e952fd82507858 to your computer and use it in GitHub Desktop.
Janet preloading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import preloader) | |
# Files that a use may want to load | |
(def mod1 (require "mod1")) | |
(def mod2 (require "mod2")) | |
(defn main [& args] | |
(preloader/preload "@mod1" mod1) | |
(preloader/preload "@mod2" mod2) | |
(dofile "some-user-file.janet")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def hi "hi") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def yo "yo") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn preload | |
"Add a module to the preload cache" | |
[name env] | |
(put module/cache name env)) | |
(defn preload-getter | |
"Given a path name, return the module if it is in the cache." | |
[x] | |
(when (string/has-prefix? "@" x) | |
(if (in module/cache x) x))) | |
(defn preload-loader | |
"Just look up a module in the cache." | |
[path &] | |
(get module/cache path)) | |
(put module/loaders :preload preload-loader) | |
(array/insert module/paths 0 [preload-getter :preload]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import @mod1 :as mod1) | |
(import @mod2 :as mod2) | |
(mod1/hi) | |
(mod2/yo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment