about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2024-04-03 23:34:46 -0500
committerCase Duckworth2024-04-03 23:34:46 -0500
commit5f94f3d439dc84fd32ce2ca75eaa867bf0668fc9 (patch)
treefe01c5815a476b72c10f84f085b9cdb8c8cc70ec
parentRefactor literals reading and implement number literals (diff)
downloadlam-5f94f3d439dc84fd32ce2ca75eaa867bf0668fc9.tar.gz
lam-5f94f3d439dc84fd32ce2ca75eaa867bf0668fc9.zip
Catch read errors
-rw-r--r--repl.lua19
1 files changed, 16 insertions, 3 deletions
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)
39 if prompt then 39 if prompt then
40 stderr = io.open("/dev/stderr", "w") -- Linux-only ! 40 stderr = io.open("/dev/stderr", "w") -- Linux-only !
41 end 41 end
42 while true do 42 while true do -- loop
43 if prompt then 43 if prompt then
44 stderr:write(prompt) 44 stderr:write(prompt)
45 stderr:flush() 45 stderr:flush()
46 end 46 end
47 local x = read.read(inport) 47 -- read
48 local ok, x = xpcall(
49 function () return read.read(inport) end,
50 function (e)
51 local start = e:find(": ")
52 return e:sub(start+2)
53 end
54 )
55 if not ok then
56 print("(read) not ok: " .. x)
57 x = nil
58 end
59 -- eval
48 if x then 60 if x then
49 local ok, val = 61 local ok, val =
50 xpcall( 62 xpcall(
@@ -55,8 +67,9 @@ function m.repl (prompt, infile, out)
55 end 67 end
56 ) 68 )
57 if not ok then 69 if not ok then
58 print("not ok: " .. val) 70 print("(eval) not ok: " .. val)
59 elseif out ~= false then 71 elseif out ~= false then
72 -- print
60 schemeprint(val) 73 schemeprint(val)
61 end 74 end
62 end 75 end