about summary refs log tree commit diff stats
path: root/main.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-05-11 13:12:13 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-05-11 13:12:13 -0700
commitba0d0028eac8cc3eeca74aff7132f1136939591a (patch)
treeda9e6b8b829416d314607533131864d820a62d16 /main.lua
parentd8e5a1ce1258b788fabc74ab2dda85dce8ab22ad (diff)
downloadlines.love-ba0d0028eac8cc3eeca74aff7132f1136939591a.tar.gz
clean up repl functionality
Now we have separate keywords for returning vs drawing something.
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua39
1 files changed, 7 insertions, 32 deletions
diff --git a/main.lua b/main.lua
index c2e6aa6..a2d0a57 100644
--- a/main.lua
+++ b/main.lua
@@ -1,5 +1,6 @@
 require 'keychord'
 require 'button'
+require 'repl'
 local utf8 = require 'utf8'
 
 lines = {}
@@ -66,8 +67,9 @@ function love.draw()
   -- cursor
   love.graphics.print('_', 25+text:getWidth()*1.5, y)
 
+  -- display side effect
   if exec_payload then
-    call_gather(exec_payload)
+    run(exec_payload)
   end
 end
 
@@ -117,9 +119,10 @@ function keychord_pressed(chord)
       end
     end
   elseif chord == 'C-r' then
-    eval(lines[#lines])
---?     lines[#lines+1] = eval(lines[#lines])[1]
---?     lines[#lines+1] = ''
+    lines[#lines+1] = eval(lines[#lines])[1]
+    lines[#lines+1] = ''
+  elseif chord == 'C-d' then
+    parse_into_exec_payload(lines[#lines])
   end
 end
 
@@ -129,31 +132,3 @@ end
 function love.mousepressed(x, y, button)
   propagate_to_button_handers(x, y, button)
 end
-
-function eval(buf)
-  local f = load('return '..buf, 'REPL')
-  if f then
-    exec_payload = f
-    return
---?     return call_gather(f)
-  end
-  local f, err = load(buf, 'REPL')
-  if f then
-    exec_payload = f
-    return
---?     return call_gather(f)
-  else
-    return {err}
-  end
-end
-
--- based on https://github.com/hoelzro/lua-repl
-function call_gather(f)
-  local success, results = gather_results(xpcall(f, function(...) return debug.traceback() end))
-  return results
-end
-
-function gather_results(success, ...)
-  local n = select('#', ...)
-  return success, { n = n, ... }
-end