lua-users home
lua-l archive

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


> Is there some sample source code showing how to use lua_pcall with 
> err_func != 0?  Basically when I'm calling into Lua and an error 
> occurs I'd like to see the debug traceback, but I'm not quite sure how 
> to do that based on the docs.

static int runfile (lua_State *L, char *name) {
	int err_func;
    lua_pushliteral(L, "_TRACEBACK");
    lua_rawget(L, LUA_GLOBALSINDEX);  /* get traceback function */
    err_func = lua_gettop (L);
    return (luaL_loadfile (L, name)) || (lua_pcall (L, 0, 0, err_func));
}

...
if (runfile (L, "file.lua"))
	fprintf (stderr, "lua: fatal error: `%s'\n", lua_tostring (L, -1));
...

	Untested code!  But I think it'll give you
a hint.
		Tomas