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:
authorAdam Lerer <alerer@fb.com>2015-04-09 20:36:31 +0300
committerAdam Lerer <alerer@fb.com>2015-04-09 22:48:18 +0300
commit6bbe44f717266dfd1c24908a4feefd5df063ee97 (patch)
tree3668fa8857d3ff4d9359af6e7b5826955efeca78
parent468aa304ba9e3dae9a836b553614f14754b563f8 (diff)
Improve error stack trace from trepl.
trepl does a trick to print the results of commands, but this trick confuses the traceback. Before: th> a=torch.Tensor(1,2) th> a:size(3) [string "local f = function() return a:size(3) end loc..."]:1: bad argument #2 to 'f' (out of range) stack traceback: [C]: in function 'f' [string "local f = function() return a:size(3) end loc..."]:1: in main chunk [C]: in function 'xpcall' ...r/git/torch-distro2/install/share/lua/5.1/trepl/init.lua:620: in function 'repl' ...ch-distro2/install/lib/luarocks/rocks/trepl/scm-1/bin/th:185: in main chunk [C]: at 0x004057d0 After: th> a=torch.Tensor(1,2) th> a:size(3) [string "_ = a:size(3)"]:1: bad argument #1 to 'size' (out of range) stack traceback: [C]: in function 'size' [string "_ = a:size(3)"]:1: in main chunk [C]: in function 'xpcall' ...r/git/torch-distro2/install/share/lua/5.1/trepl/init.lua:623: in function 'repl' ...ch-distro2/install/lib/luarocks/rocks/trepl/scm-1/bin/th:185: in main chunk [C]: at 0x004057d0
-rw-r--r--init.lua10
1 files changed, 7 insertions, 3 deletions
diff --git a/init.lua b/init.lua
index 75961be..c4a83f6 100644
--- a/init.lua
+++ b/init.lua
@@ -615,10 +615,14 @@ function repl()
local err
if not (line:find(';%s-$') or line:find('^%s-print')) then
-- Try to compile statement with "return", to auto-print
- local parsed = loadstring('local f = function() return '..line..' end local res = {f()} print(unpack(res)) table.insert(_RESULTS,res[1])')
+ local parsed = loadstring('local f = function() return '..line..' end')
if parsed then
- local ok,err = xpcall(parsed, traceback)
- if not ok then
+ local parsed = loadstring('_RESULT={'..line..'}')
+ local ok,err=xpcall(parsed, traceback)
+ if ok then
+ print(unpack(_RESULT))
+ table.insert(_RESULTS,_RESULT[1])
+ else
print(err)
end
done = true