copy how Lua 5.3 REPL prints expr values
This commit is contained in:
parent
45508a440f
commit
dfd67aed3c
17
mu.lua
17
mu.lua
|
@ -5,9 +5,6 @@ curses.echo(false) -- unclear why implicit echo can't handle newlines, regardles
|
|||
stdscr:clear()
|
||||
stdscr:scrollok(true)
|
||||
|
||||
-- unclear how Lua (post 5.2) is able to selectively print values of variables
|
||||
-- at the repl
|
||||
|
||||
local function gather_results(success, ...)
|
||||
local n = select('#', ...)
|
||||
return success, { n = n, ... }
|
||||
|
@ -34,6 +31,19 @@ while true do
|
|||
stdscr:addstr('>> ')
|
||||
end
|
||||
buf = buf .. readline()
|
||||
local f, err = load('return '..buf, 'REPL')
|
||||
if f then
|
||||
buf = ''
|
||||
new_expr = true
|
||||
local success, results = gather_results(xpcall(f, function(...) return debug.traceback() end))
|
||||
if success then
|
||||
for _, result in ipairs(results) do
|
||||
print(result)
|
||||
end
|
||||
else
|
||||
print(results[1])
|
||||
end
|
||||
else
|
||||
local f, err = load(buf, 'REPL')
|
||||
if f then
|
||||
buf = ''
|
||||
|
@ -58,5 +68,6 @@ while true do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
curses.endwin()
|
||||
|
|
Loading…
Reference in New Issue