luaa: add stack dumping debug function

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-10-20 11:21:15 +02:00
parent 7d34f45ed6
commit e39535c9fd
1 changed files with 37 additions and 0 deletions

37
luaa.h
View File

@ -23,9 +23,12 @@
#define AWESOME_LUA_H #define AWESOME_LUA_H
#include <ev.h> #include <ev.h>
#include <lua.h> #include <lua.h>
#include <lauxlib.h> #include <lauxlib.h>
#include <stdio.h>
#include "draw.h" #include "draw.h"
#include "common/util.h" #include "common/util.h"
@ -92,6 +95,40 @@ typedef int luaA_ref;
luaL_error(L, "invalid screen number: %d", screen + 1); \ luaL_error(L, "invalid screen number: %d", screen + 1); \
} while(0) } 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");
}
/** Check that an object is not a NULL reference. /** Check that an object is not a NULL reference.
* \param L The Lua state. * \param L The Lua state.
* \param ud The index of the object in the stack. * \param ud The index of the object in the stack.