From c542b03f5a50ad0fb5d283c39c662bc7fbe97db4 Mon Sep 17 00:00:00 2001 From: unwox Date: Fri, 6 Dec 2024 16:34:34 +0600 Subject: implement module reloading from neovim --- bin/serve.fnl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'bin/serve.fnl') 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})))) -- cgit v1.2.3