lua-users home
lua-l archive

Re: Creating a default error handler for lua_pcall

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


Lee Hickey wrote:
On 26/03/07, *Alex Queiroz* <asandroq@gmail.com <mailto:asandroq@gmail.com>> wrote:
 Hallo,
 On 3/26/07, Lee Hickey <lahickey@gmail.com
 <mailto:lahickey@gmail.com>> wrote:
 >
 > Is there a standard way to set a 'default' error handler for
 lua_pcall,
 > rather than the usual method of inserting a c function into the
 stack before
 > each pcall. I am currently setting up a global error handling
 function
 > immediately after creating a lua_State, and using this, but this
 is prone to
 > being obliterated by any C code which doesn't respect the stack
 properly.
 >
 You can create a C function my_pcall() that takes one less
 parameter and always push
 your customized error handler on the stack.
 Cheers,
Thanks. What I forgot to mention is that I want to remove the overhead of having to insert this extra parameter for every pcall. My game engine makes many pcalls and I would rather have each of these calls be as cheap as possible. This need isn't based on any kind of profiling, so I am guilty of a little blind optimising, but many unnecessary lua_inserts per frame seems like a sensible thing to avoid if at all possible.
Regards,
Lee.
It's probably not that expensive. But you might want to try to cut down on the number of pcalls, for example by using an "outer pcall" which calls function which performs a sequence of lua functions. (Of course, you could also seek & destroy C functions which don't conform to your stack guidelines.)

AltStyle によって変換されたページ (->オリジナル) /