-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepl.fnl
More file actions
41 lines (34 loc) · 1.13 KB
/
repl.fnl
File metadata and controls
41 lines (34 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
(local coroutine (require :coroutine))
(local fennel (require :fennel))
(local jeejah (require :jeejah))
(local {:merge merge}
(require :lib.functional))
(fn fennel-middleware [f msg]
(match msg.op
"load-file" (let [f (assert (io.open msg.filename "rb"))]
(tset msg
:op "eval"
:code (-> f
(: :read "*all")
(: :gsub "^#![^\n]*\n" "")))
(: f :close))
_ (f msg)))
(local default-opts {:port nil
:fennel true
:middleware fennel-middleware
:serialize hs.inspect})
(local repl-coro-freq 0.05)
(fn run [server]
(let [repl-coro server
repl-spin (fn [] (coroutine.resume repl-coro))
repl-chk (fn [] (not= (coroutine.status repl-coro) "dead"))]
(hs.timer.doWhile repl-chk repl-spin repl-coro-freq)))
(fn start [custom-opts]
(let [opts (merge {} default-opts custom-opts)
server (jeejah.start opts.port opts)]
server))
(fn stop [server]
(jeejah.stop server))
{: run
: start
: stop}