From a8f4a59efdeabe49e9d7295e711e1868cbd53ede Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 25 Jun 2009 15:46:42 +0200 Subject: [PATCH] lualib: import stack dumping function Signed-off-by: Julien Danjou --- common/lualib.h | 34 ++++++++++++++++++++++++++++++++++ luaa.h | 34 ---------------------------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/common/lualib.h b/common/lualib.h index a09badbb1..c9288d5a8 100644 --- a/common/lualib.h +++ b/common/lualib.h @@ -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. diff --git a/luaa.h b/luaa.h index a0475979b..79fd89a2e 100644 --- a/luaa.h +++ b/luaa.h @@ -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) {