diff options
author | Case Duckworth | 2024-04-02 21:04:52 -0500 |
---|---|---|
committer | Case Duckworth | 2024-04-02 21:04:52 -0500 |
commit | 5c2508b5091fe5b799506d8b6beef77e962bc99c (patch) | |
tree | 9c6533140a13db1aa53391219da2978b8b1618c4 | |
parent | Change arity assertion code (diff) | |
download | lam-5c2508b5091fe5b799506d8b6beef77e962bc99c.tar.gz lam-5c2508b5091fe5b799506d8b6beef77e962bc99c.zip |
Protect evaluation within repl
-rw-r--r-- | repl.lua | 13 |
1 files changed, 11 insertions, 2 deletions
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) | |||
33 | end | 33 | end |
34 | local x = read.read(inport) | 34 | local x = read.read(inport) |
35 | if x then | 35 | if x then |
36 | local val = eval.eval(x) | 36 | local ok, val = |
37 | if out ~= false then | 37 | xpcall( |
38 | function () return eval.eval(x) end, | ||
39 | function (e) | ||
40 | local start = e:find(": ") | ||
41 | return e:sub(start+2) | ||
42 | end | ||
43 | ) | ||
44 | if not ok then | ||
45 | print("not ok: " .. val) | ||
46 | elseif out ~= false then | ||
38 | schemeprint(val) | 47 | schemeprint(val) |
39 | end | 48 | end |
40 | end | 49 | end |