Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/trepl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClement Farabet <clement.farabet@gmail.com>2014-03-19 19:13:20 +0400
committerClement Farabet <clement.farabet@gmail.com>2014-03-19 19:13:20 +0400
commit3dc150012868cb608196561033162f37155e2492 (patch)
treeaabbb16923e02880e16697323627200069ff9d5f
parent2142a60caaad91f74712fefd6b2d4f345ef9a1b0 (diff)
Better error handling (in the readline parser)
-rw-r--r--init.lua16
-rw-r--r--th1
2 files changed, 15 insertions, 2 deletions
diff --git a/init.lua b/init.lua
index 95979f4..766337d 100644
--- a/init.lua
+++ b/init.lua
@@ -472,20 +472,32 @@ $endif
-- try to return first:
timer_start()
- local ok,err
+ local pok,ok,err
if line:find(';%s-$') or line:find('^%s-print') then
ok = false
elseif line:match('^%s*$') then
return nil
else
- ok,err = xpcall(loadstring('local f = function() return '..line..' end local res = {f()} print(unpack(res)) table.insert(_RESULTS,res[1])'), traceback)
+ local func, perr = loadstring('local f = function() return '..line..' end local res = {f()} print(unpack(res)) table.insert(_RESULTS,res[1])')
+ if func then
+ pok = true
+ ok,err = xpcall(func, traceback)
+ end
end
+
+ -- run ok:
if ok then
_LAST = _RESULTS[#_RESULTS]
timer_stop()
return line
end
+ -- parsed ok, but failed to run (code error):
+ if pok then
+ print(err)
+ return cmd:sub(1, -2)
+ end
+
-- continue to get lines until get a complete chunk
local func, err
while true do
diff --git a/th b/th
index 7bb741b..554865f 100644
--- a/th
+++ b/th
@@ -95,6 +95,7 @@ if statement then
local ok,res = pcall(s)
if not ok then
print('could not execute statement, skipping')
+ error(res)
end
-- quit by default
if not interactive then os.exit() end