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:
authorSoumith Chintala <soumith@gmail.com>2015-11-03 09:22:24 +0300
committerSoumith Chintala <soumith@gmail.com>2015-11-03 09:22:24 +0300
commitfa8074920c88ced39dc1b348af7db5f5e61863a4 (patch)
tree1bc78b42b61cc08f218deeca0457b61582f3373d
parentdbd6f741df40cb765f176693e28f3aecb41745d4 (diff)
xpcall + debug stack around library loading in thlibloading
-rw-r--r--th14
1 files changed, 13 insertions, 1 deletions
diff --git a/th b/th
index c90f23a..a5c8ee2 100644
--- a/th
+++ b/th
@@ -2,6 +2,17 @@
loadstring = loadstring or load -- for lua 5.2 compat
+-- Tracekback (error printout)
+local function traceback(message)
+ local tp = type(message)
+ if tp ~= "string" and tp ~= "number" then return message end
+ local debug = _G.debug
+ if type(debug) ~= "table" then return message end
+ local tb = debug.traceback
+ if type(tb) ~= "function" then return message end
+ return tb(message)
+end
+
-- help
local help = [==[
Usage: th [options] [script.lua [arguments]]
@@ -34,9 +45,10 @@ for _,arg in ipairs(parg) do
end
-- load libraries
if lib then
- local ok = pcall(require,lib)
+ local ok, err = xpcall(function() require(lib) end, traceback)
if not ok then
print('could not load ' .. lib .. ', skipping')
+ print(err)
end
elseif progargs then
-- program args