From 36a1e1789677dbdb2497f0ba8022c2561792d5fc Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 25 Apr 2022 22:23:25 -0700 Subject: [PATCH] . --- mu.lua | 12 +++++++----- 1 file 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 = ''