diff --git a/luaa.h b/luaa.h index 844996311..2f4d8e1dc 100644 --- a/luaa.h +++ b/luaa.h @@ -23,9 +23,12 @@ #define AWESOME_LUA_H #include + #include #include +#include + #include "draw.h" #include "common/util.h" @@ -92,6 +95,40 @@ typedef int luaA_ref; 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"); +} + /** Check that an object is not a NULL reference. * \param L The Lua state. * \param ud The index of the object in the stack.