diff options
| author | unwox <me@unwox.com> | 2024-12-06 16:34:34 +0600 |
|---|---|---|
| committer | unwox <me@unwox.com> | 2024-12-06 19:57:44 +0600 |
| commit | c542b03f5a50ad0fb5d283c39c662bc7fbe97db4 (patch) | |
| tree | 2805dc4c3a424b516919b417788cb674ff9310c5 /bin/serve.fnl | |
| parent | 9c446e241e067eb7d3846d811773d1a358abcd13 (diff) | |
implement module reloading from neovim
Diffstat (limited to 'bin/serve.fnl')
| -rw-r--r-- | bin/serve.fnl | 20 |
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})))) |
