Add a debugging function that prints out the contents of the Lua stack
This commit is contained in:
parent
744cdb2085
commit
cc1069734c
2 changed files with 22 additions and 1 deletions
|
@ -840,8 +840,25 @@ void luaW_pushconfig(lua_State *L, const config& cfg)
|
|||
luaW_filltable(L, cfg);
|
||||
}
|
||||
|
||||
luaW_PrintStack luaW_debugstack(lua_State* L) {
|
||||
return {L};
|
||||
}
|
||||
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const luaW_PrintStack& s) {
|
||||
int top = lua_gettop(s.L);
|
||||
os << "Lua Stack\n";
|
||||
for(int i = 1; i <= top; i++) {
|
||||
luaW_getglobal(s.L, "wesnoth", "as_text");
|
||||
lua_pushvalue(s.L, i);
|
||||
lua_call(s.L, 1, 1);
|
||||
auto value = luaL_checkstring(s.L, -1);
|
||||
lua_pop(s.L, 1);
|
||||
os << '[' << i << ']' << value << '\n';
|
||||
}
|
||||
if(top == 0) os << "(empty)\n";
|
||||
os << std::flush;
|
||||
return os;
|
||||
}
|
||||
|
||||
#define return_misformed() \
|
||||
do { lua_settop(L, initial_top); return false; } while (0)
|
||||
|
|
|
@ -225,6 +225,10 @@ int luaW_pcall_internal(lua_State *L, int nArgs, int nRets);
|
|||
int luaW_type_error(lua_State *L, int narg, const char *tname);
|
||||
int luaW_type_error(lua_State *L, int narg, const char* kpath, const char *tname);
|
||||
|
||||
struct luaW_PrintStack { lua_State* L; };
|
||||
luaW_PrintStack luaW_debugstack(lua_State* L);
|
||||
std::ostream& operator<<(std::ostream& os, const luaW_PrintStack&);
|
||||
|
||||
#define deprecate_attrib(name, prefix, level, version, msg) deprecated_message(prefix "." name, DEP_LEVEL::level, version, msg)
|
||||
|
||||
#define return_deprecated_attrib(type_macro, name, accessor, prefix, level, version, msg) \
|
||||
|
|
Loading…
Add table
Reference in a new issue