about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-04-25 22:23:25 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-04-25 22:24:26 -0700
commit36a1e1789677dbdb2497f0ba8022c2561792d5fc (patch)
treea4c5aa4c3e308ae94db93f7a8c71e8ec09f350b8
parenta200d713ef762a5fbaf575531c62400fd827a0fd (diff)
downloadtext.love-36a1e1789677dbdb2497f0ba8022c2561792d5fc.tar.gz
.
-rw-r--r--mu.lua12
1 files changed, 7 insertions, 5 deletions
diff --git a/mu.lua b/mu.lua
index 7469920..be56705 100644
--- a/mu.lua
+++ b/mu.lua
@@ -5,11 +5,6 @@ curses.echo(false) -- unclear why implicit echo can't handle newlines, regardles
 stdscr:clear()
 stdscr:scrollok(true)
 
-local function gather_results(success, ...)
-  local n = select('#', ...)
-  return success, { n = n, ... }
-end
-
 local function readline()
   local result = ''
   while true do
@@ -22,6 +17,7 @@ local function readline()
   return result
 end
 
+-- based on https://github.com/hoelzro/lua-repl
 function eval_print(f)
   local success, results = gather_results(xpcall(f, function(...) return debug.traceback() end))
   if success then
@@ -37,6 +33,11 @@ function eval_print(f)
   stdscr:addch('\n')
 end
 
+local function gather_results(success, ...)
+  local n = select('#', ...)
+  return success, { n = n, ... }
+end
+
 local new_expr = true
 local buf = ''
 while true do
@@ -46,6 +47,7 @@ while true do
     stdscr:addstr('>> ')
   end
   buf = buf .. readline()
+  -- print value of expression the way Lua 5.3 does it: by prepending 'return' to the line
   local f = load('return '..buf, 'REPL')
   if f then
     buf = ''