[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re[2]: getting call stack in case of a run-time error
- From: Tomas <tomas@...>
- Date: Wed, 21 Apr 2004 14:40:40 -0300 (BRT)
Hi Dmitriy,
> I tried it after run-time error inside a lua thread. Now
I'm sorry. I forgot to mention that you to use it inside
a "xpcall". For instance, supose you want to call function x
with a set of different arguments:
function x (s)
return '('..s..')'
end
for _, s in ipairs{ "abc", 23, {} } do
local ok, msg_or_str = xpcall (function () return x(s) end, debug.traceback)
if ok then
print ("Ok!", msg_or_str)
else
print ("Fail!", msg_or_str)
end
end
The arguments are on the table { "abc", 23, {} }.
Ok! (abc)
Ok! (23)
Fail! test.lua:2: attempt to concatenate local `s' (a table value)
stack traceback:
test.lua:2: in function `x'
(tail call): ?
[C]: in function `xpcall'
test.lua:6: in main chunk
[C]: ?
The error message was created by debug.traceback and returned
by xpcall as the second return value. `test.lua` is the name of the
file where the code was written.
Tomas