diff options
author | Soumith Chintala <soumith@gmail.com> | 2015-11-03 09:26:09 +0300 |
---|---|---|
committer | Soumith Chintala <soumith@gmail.com> | 2015-11-03 09:26:09 +0300 |
commit | 2492b1f45336f38859f031bf23af72bd52a37568 (patch) | |
tree | 1bc78b42b61cc08f218deeca0457b61582f3373d | |
parent | 39d3b4b99397dbb57c817f87747d09e5f445e3b5 (diff) | |
parent | fa8074920c88ced39dc1b348af7db5f5e61863a4 (diff) |
Merge pull request #40 from torch/libloading
xpcall + debug stack around library loading in th
-rw-r--r-- | th | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -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 |