diff options
author | Clement Farabet <clement.farabet@gmail.com> | 2014-03-19 19:13:20 +0400 |
---|---|---|
committer | Clement Farabet <clement.farabet@gmail.com> | 2014-03-19 19:13:20 +0400 |
commit | 3dc150012868cb608196561033162f37155e2492 (patch) | |
tree | aabbb16923e02880e16697323627200069ff9d5f | |
parent | 2142a60caaad91f74712fefd6b2d4f345ef9a1b0 (diff) |
Better error handling (in the readline parser)
-rw-r--r-- | init.lua | 16 | ||||
-rw-r--r-- | th | 1 |
2 files changed, 15 insertions, 2 deletions
@@ -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 @@ -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 |