From 5f94f3d439dc84fd32ce2ca75eaa867bf0668fc9 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 3 Apr 2024 23:34:46 -0500 Subject: Catch read errors --- repl.lua | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'repl.lua') diff --git a/repl.lua b/repl.lua index c2233c4..be739c7 100644 --- a/repl.lua +++ b/repl.lua @@ -39,12 +39,24 @@ function m.repl (prompt, infile, out) if prompt then stderr = io.open("/dev/stderr", "w") -- Linux-only ! end - while true do + while true do -- loop if prompt then stderr:write(prompt) stderr:flush() end - local x = read.read(inport) + -- read + local ok, x = xpcall( + function () return read.read(inport) end, + function (e) + local start = e:find(": ") + return e:sub(start+2) + end + ) + if not ok then + print("(read) not ok: " .. x) + x = nil + end + -- eval if x then local ok, val = xpcall( @@ -55,8 +67,9 @@ function m.repl (prompt, infile, out) end ) if not ok then - print("not ok: " .. val) + print("(eval) not ok: " .. val) elseif out ~= false then + -- print schemeprint(val) end end -- cgit 1.4.1-21-gabe81