lua-users home
lua-l archive

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


On Wed, Nov 19, 2003 at 03:07:12PM +0800, Brett Bibby wrote:
> 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?

you need to push your function onto the stack.  as an example, look at
function lcall() in src/lua/lua.c: it gets the function registered under
the name "_TRACEBACK", moves that function to stack index 'base' (which
is below the chunk which is going to be executed and its arguments), and
then calls lua_pcall(..., base) to execute the chunk.

in this case, the error handling function is errorfb() from src/lib/ldblib.c.
it is registered with the name "_TRACEBACK" in luaopen_debug(), and is a
nice example of how to use the debug interface (lua_getstack(), lua_getinfo(),
etc.)

hope that helps.

-taj