lua-users home
lua-l archive

Re: lua_resume() and error handling.

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


Hi,
Martin Stone wrote:
> Is it possible to customize error handling when using lua_resume() in
> the same way that one can with lua_pcall()? Reading the source to
> lua_pcall() doesn't make it look simple!
The approach is different. lua_pcall() allows you to set up an
error printing routine that is called before the stack is unwound.
lua_resume() does not unwind the stack on error (but declares
the coroutine 'dead').
So you can just inspect the stack after lua_resume() returns
with an error and print a traceback. Have a look at what
debug.traceback() does (db_errorfb in ldblib.c) or just call it
from C or Lua.
However ... this feature requires Lua 5.1-work2 or above.
See this message for an announcement and an example:
 http://lua-users.org/lists/lua-l/2004-09/msg00413.html
(but don't download work2, we are at work6 now)
BTW: I'm not sure who is in charge of the mailing list archive,
 but the index seems to be broken. Enter 'Lua 5.1 work 2'
 (without the quotes) as a search string and look at the
 top message found. The results list shows a completely
 unrelated message, but the link points to the correct one.
 Strange. Same thing happens with other searches, too.
Bye,
 Mike

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