From 5c2508b5091fe5b799506d8b6beef77e962bc99c Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 2 Apr 2024 21:04:52 -0500 Subject: Protect evaluation within repl --- repl.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'repl.lua') diff --git a/repl.lua b/repl.lua index 556525c..93e430c 100644 --- a/repl.lua +++ b/repl.lua @@ -33,8 +33,17 @@ function m.repl (prompt, infile, out) end local x = read.read(inport) if x then - local val = eval.eval(x) - if out ~= false then + local ok, val = + xpcall( + function () return eval.eval(x) end, + function (e) + local start = e:find(": ") + return e:sub(start+2) + end + ) + if not ok then + print("not ok: " .. val) + elseif out ~= false then schemeprint(val) end end -- cgit 1.4.1-21-gabe81