is that what u like ?
int CLuaCallBacks::_print(lua_State *lua)//DirectCallFunction
{
lua_pushlightuserdata(lua, pid);
lua_gettable(lua, LUA_REGISTRYINDEX);
CLuaScript *pThis = (CLuaScript *)lua_touserdata(lua, -1);
if(!pThis) return 0;
int n = lua_gettop(lua); //number of arguments
for (int i = 1; i < n; i++)
{
pThis->Print("%s\r\n",lua_tostring(lua, i));
}
return 0;
}
----- Original Message -----
*From:* joe rossi <mailto:bigcirde@yahoo.com>
*To:* lua@bazar2.conectiva.com.br
<mailto:lua@bazar2.conectiva.com.br>
*Sent:* Saturday, March 11, 2006 11:04 PM
*Subject:* Lua 5.1f: How to dump stack contents from C?
I'm using Lua 5.1 final, and I need a stack dump function. What I
came up with doesn't seem to print accurately, or anything at
all. Does anyone know how I might change this to make it work ?
It's very difficult for me to work if I cannot see my Lua error
messages:
static void stackDump (lua_State *L) {
int i=lua_gettop(L);
printf(" ---------------- Stack Dump ----------------" );
while( i ) {
int t = lua_type(L, i);
switch (t) {
case LUA_TSTRING:
printf("%d:`%s'", i, lua_tostring(L, i));
break;
case LUA_TBOOLEAN:
printf("%d: %s",i,lua_toboolean(L, i) ? "true" : "false");
break;
case LUA_TNUMBER:
printf("%d: %g", i, lua_tonumber(L, i));
break;
default: printf("%d: %s", i, lua_typename(L, t)); break;
}
i--;
}
printf("--------------- Stack Dump Finished ---------------" );
}
------------------------------------------------------------------------
Relax. Yahoo! Mail virus scanning
<http://us.rd.yahoo.com/mail_us/taglines/virusall/*http://communications.yahoo.com/features.php?page=221>
helps detect nasty viruses!