summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorunwox <me@unwox.com>2024-12-06 16:34:34 +0600
committerunwox <me@unwox.com>2024-12-06 19:57:44 +0600
commitc542b03f5a50ad0fb5d283c39c662bc7fbe97db4 (patch)
tree2805dc4c3a424b516919b417788cb674ff9310c5 /bin
parent9c446e241e067eb7d3846d811773d1a358abcd13 (diff)
implement module reloading from neovim
Diffstat (limited to 'bin')
-rw-r--r--bin/serve.fnl20
1 files changed, 20 insertions, 0 deletions
diff --git a/bin/serve.fnl b/bin/serve.fnl
index c7bc334..8cdd673 100644
--- a/bin/serve.fnl
+++ b/bin/serve.fnl
@@ -17,6 +17,24 @@
(when _G.unpack
(tset table :unpack _G.unpack))
+(set _G.reload
+ (fn [module]
+ (local old (require module))
+ (tset package :loaded module nil)
+ (local (ok? new) (pcall require module))
+ (if (not ok?)
+ (do
+ (tset package :loaded module old)
+ (error new))
+ (when (= (type new) :table)
+ (do
+ (each [k v (pairs new)]
+ (tset old k v))
+ (each [k (pairs old)]
+ (when (not (. new k))
+ (tset old k nil)))
+ (tset package :loaded module old))))))
+
(local db (must (luna.db.open "file:var/db.sqlite?_journal=WAL&_sync=NORMAL")))
(local query-synonyms {
@@ -582,3 +600,5 @@
(must (luna.router.route "GET /" root-handler))
(must (luna.router.route "GET /robots.txt" robots-handler))
(must (luna.router.static "GET /static/" "static/"))
+
+(must (luna.repl (fn [code] (fennel.eval code {:env _G}))))