summaryrefslogtreecommitdiff
path: root/bin/serve.fnl
diff options
context:
space:
mode:
authorunwox <me@unwox.com>2024-12-23 23:00:42 +0600
committerunwox <me@unwox.com>2024-12-23 23:00:42 +0600
commitc2bf2853b4319acb2a5e6b90e71014552bc67aec (patch)
treee9e42775f94f0c7c6845cefb1eff15e5553fb7ce /bin/serve.fnl
parentaa9460bb7132571e66171884b6d1f4625399fb6d (diff)
implement module reloading
Diffstat (limited to 'bin/serve.fnl')
-rw-r--r--bin/serve.fnl21
1 files changed, 21 insertions, 0 deletions
diff --git a/bin/serve.fnl b/bin/serve.fnl
index b18d842..de5b4b3 100644
--- a/bin/serve.fnl
+++ b/bin/serve.fnl
@@ -3,6 +3,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))))))
+
(fn ends-with [str end]
(= (string.sub str (- (# end))) end))
@@ -32,3 +50,6 @@
(luna.router.route "GET /" router)
(luna.router.static "GET /static/" "static/")
+
+(when luna.debug
+ (luna.evalfn (fn [code] (fennel.eval code {:env _G}))))