lualib: import stack dumping function

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-06-25 15:46:42 +02:00
parent 284338532b
commit a8f4a59efd
2 changed files with 34 additions and 34 deletions

View File

@ -31,6 +31,40 @@
luaL_typerror(L, n, "function"); \
} while(0)
/** Dump the Lua stack. Useful for debugging.
* \param L The Lua VM state.
*/
static inline void
luaA_dumpstack(lua_State *L)
{
fprintf(stderr, "-------- Lua stack dump ---------\n");
for(int i = lua_gettop(L); i; i--)
{
int t = lua_type(L, i);
switch (t)
{
case LUA_TSTRING:
fprintf(stderr, "%d: string: `%s'\n", i, lua_tostring(L, i));
break;
case LUA_TBOOLEAN:
fprintf(stderr, "%d: bool: %s\n", i, lua_toboolean(L, i) ? "true" : "false");
break;
case LUA_TNUMBER:
fprintf(stderr, "%d: number: %g\n", i, lua_tonumber(L, i));
break;
case LUA_TNIL:
fprintf(stderr, "%d: nil\n", i);
break;
default:
fprintf(stderr, "%d: %s\t#%d\t%p\n", i, lua_typename(L, t),
(int) lua_objlen(L, i),
lua_topointer(L, i));
break;
}
}
fprintf(stderr, "------- Lua stack dump end ------\n");
}
/** Convert s stack index to positive.
* \param L The Lua VM state.
* \param ud The index.

34
luaa.h
View File

@ -56,40 +56,6 @@
luaL_error(L, "invalid screen number: %d", screen + 1); \
} while(0)
/** Dump the Lua stack. Useful for debugging.
* \param L The Lua VM state.
*/
static inline void
luaA_dumpstack(lua_State *L)
{
fprintf(stderr, "-------- Lua stack dump ---------\n");
for(int i = lua_gettop(L); i; i--)
{
int t = lua_type(L, i);
switch (t)
{
case LUA_TSTRING:
fprintf(stderr, "%d: string: `%s'\n", i, lua_tostring(L, i));
break;
case LUA_TBOOLEAN:
fprintf(stderr, "%d: bool: %s\n", i, lua_toboolean(L, i) ? "true" : "false");
break;
case LUA_TNUMBER:
fprintf(stderr, "%d: number: %g\n", i, lua_tonumber(L, i));
break;
case LUA_TNIL:
fprintf(stderr, "%d: nil\n", i);
break;
default:
fprintf(stderr, "%d: %s\t#%d\t%p\n", i, lua_typename(L, t),
(int) lua_objlen(L, i),
lua_topointer(L, i));
break;
}
}
fprintf(stderr, "------- Lua stack dump end ------\n");
}
static inline bool
luaA_checkboolean(lua_State *L, int n)
{