lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Is there any significant performance overhead when running in protected mode?


On 1/24/07, Matthew Armstrong < turkeypotpie@gmail.com> wrote:
Cool, thank you so much.

The response time on this mailing list is insane :P



On 1/24/07, Rici Lake < lua@ricilake.net > wrote:

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.