[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: simplest way to trap error in lua?
- From: Rici Lake <lua@...>
- Date: Thu, 25 Jan 2007 00:54:09 -0500
On 25-Jan-07, at 12:22 AM, Matthew Armstrong wrote:
Giving a simple example:
function f1()
local ohNoImNil = nil
ohNoImNil()
end
function f2()
f1()
end
f2()
What's the easiest way to trap the nil call and dump the stack?
easiest within lua?
> function f1()
>> local ohNoImNil = nil
>> ohNoImNil()
>> end
>
> function f2()
>> f1()
>> end
>
> ok, err = xpcall(f2, debug.traceback)
> =ok
false
> =err
stdin:3: attempt to call local 'ohNoImNil' (a nil value)
stack traceback:
stdin:3: in function 'f1'
stdin:2: in function <stdin:1>
[C]: in function 'xpcall'
stdin:1: in main chunk
[C]: ?
easiest within c?
lua_pcall(), having put debug.traceback on the stack somewhere and
providing it's index as the fourth argument.