lua-users home
lua-l archive

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

I've been following the mailing list, and I did quite a bit with Lua4 (from
the C side) for one project, and in general find Lua5 to be a wonderful
upgrade (provided that one takes the "auxiliary library" as a true core
piece), however, I am learning that I am still far from a Lua expert.

For one thing, to date I've just used the default error handler ("index" 0)
and replaced _ALERT, so I may be missing something in just "stating the
obvious", but I really expect that the "obvious" is all there is to it for
"the index of the error handler".

If you can get the error handler on the stack (either with
lua_pushcfunction, or pulling it from the registry, or whatever), then just
call lua_gettop right then, and store off the result.  This should be "the
index of the error handler".  It is important to note that this is a stack
index and so is not a globally usable value (i.e. you can't just reuse the
stack index in some other Lua called C function), however, lua_pcall will
not remove the function from the stack so on return from lua_pcall it will
still be at the same stack index.

-----Original Message-----
[]On Behalf Of Brett Bibby
Sent: Wednesday, November 19, 2003 1:07 AM
To: Lua list
Subject: Re: Lua Debug Examples

Thanks for the post.  I did have a look at them and the problem is I'm
still at the I-use-Lua-but-I-don't-quite-get-how-it-works-stage :-)  So
let me start with a simpler question.  I want to catch lua source errors
so I think I need to use lua_pcall instead of lua_call.  lua_pcall takes
a stack index for an error handler function.  On startup I registered an
error handler function, so I'm gueesing I need to pass the index of that
function to lua_pcall?  How do I get the index?  I can use
lua_pushstring of the function name and then lua_gettable to retrieve a
function, then push parameters and call it, but how do I get the index
of the function so I can pass it to lua_pcall?

----- Original Message -----
From: "Taj Khattra" <>
To: "Lua list" <>
Sent: Wednesday, November 19, 2003 1:39 PM
Subject: Re: Lua Debug Examples

> On Wed, Nov 19, 2003 at 11:48:58AM +0800, Brett Bibby wrote:
> > We're trying to implement a robust lua debugging interface and while
> > manual briefly explains the different mechanisms I couldn't find any
> > exmaples of how to use it.  Are there any complete examples that
> > how to write a pcall error function that shows how to extract the
> > info in C?  Also, does anybody have any reocmmendations on how to
set up
> > the hooks and callbacks?
> the default lua interpreter (in src/lua/lua.c) and the debug library
> (in src/lib/ldblib.c) are a useful source of examples on how to use
> lua_pcall() and the debug interface from C.
> -taj