2021-03-29 05:03:43 +00:00
|
|
|
(local util (require :lib.util))
|
|
|
|
(local fennel (require :lib.fennel))
|
|
|
|
(local style (require :core.style))
|
|
|
|
(local lume (require :lib.lume))
|
2021-04-04 02:35:50 +00:00
|
|
|
(local {: textbutton} (util.require :editor.imstate))
|
2021-04-11 18:08:57 +00:00
|
|
|
(local {: inspect} (util.require :inspector))
|
2021-03-30 23:24:52 +00:00
|
|
|
(local repl (util.hot-table ...))
|
2021-03-29 05:03:43 +00:00
|
|
|
|
2021-04-11 18:08:57 +00:00
|
|
|
(fn repl.inspector [{: vals : states} view x y]
|
2021-03-29 05:03:43 +00:00
|
|
|
(var h 0)
|
|
|
|
(each [i v (ipairs vals)]
|
2021-04-11 18:08:57 +00:00
|
|
|
(set h (+ h (inspect (. states i) v view x (+ y h) view.size.x))))
|
2021-03-29 05:03:43 +00:00
|
|
|
(+ h style.padding.y))
|
|
|
|
|
|
|
|
(fn repl.notify [listeners line]
|
|
|
|
(each [_ listener (ipairs listeners)]
|
|
|
|
(listener:append line)))
|
|
|
|
|
2021-04-04 02:35:50 +00:00
|
|
|
(fn repl.mk-result [vals]
|
2021-03-30 23:24:52 +00:00
|
|
|
(local inspector #(repl.inspector $...))
|
2021-04-11 18:08:57 +00:00
|
|
|
{:draw inspector : vals :states (icollect [_ (ipairs vals)] {})})
|
2021-04-04 02:35:50 +00:00
|
|
|
|
|
|
|
(fn repl.run [{: listeners}]
|
2021-03-29 05:03:43 +00:00
|
|
|
(fennel.repl {:readChunk coroutine.yield
|
2021-04-04 02:35:50 +00:00
|
|
|
:onValues #(repl.notify listeners (repl.mk-result $1))
|
|
|
|
:onError (fn [errType err luaSource] (repl.notify listeners (repl.mk-result [err])))
|
2021-03-29 05:03:43 +00:00
|
|
|
:pp #$1
|
|
|
|
:env (lume.clone _G)}))
|
|
|
|
|
|
|
|
(fn repl.listen [{: listeners} listener]
|
|
|
|
(table.insert listeners listener))
|
|
|
|
|
|
|
|
(fn repl.unlisten [{: listeners} listener]
|
|
|
|
(lume.remove listeners listener))
|
|
|
|
|
|
|
|
(fn repl.submit [{: coro} chunk]
|
|
|
|
(coroutine.resume coro (.. chunk "\n")))
|
|
|
|
|
|
|
|
(fn repl.new []
|
|
|
|
(local result
|
|
|
|
{:listeners []
|
2021-03-30 23:24:52 +00:00
|
|
|
:listen #(repl.listen $...)
|
|
|
|
:unlisten #(repl.unlisten $...)
|
|
|
|
:submit #(repl.submit $...)
|
2021-03-29 05:03:43 +00:00
|
|
|
:coro (coroutine.create repl.run)})
|
|
|
|
(coroutine.resume result.coro result)
|
|
|
|
result)
|
|
|
|
|
2021-03-30 23:24:52 +00:00
|
|
|
repl.hot
|