Created
September 23, 2019 18:40
-
-
Save leodido/ee40e3ad09a13bcc91af5407d9e69204 to your computer and use it in GitHub Desktop.
Dump the Lua stack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* dump_stack(ls); | |
*/ | |
void dump_stack(lua_State *L) | |
{ | |
int i; | |
int top = lua_gettop(L); | |
printf("\n#### BOS ####\n"); | |
for(i = top; i >= 1; i--) | |
{ | |
int t = lua_type(L, i); | |
switch(t) | |
{ | |
case LUA_TSTRING: | |
printf("%i (%i) = `%s'", i, i - (top + 1), lua_tostring(L, i)); | |
break; | |
case LUA_TBOOLEAN: | |
printf("%i (%i) = %s", i, i - (top + 1), lua_toboolean(L, i) ? "true" : "false"); | |
break; | |
case LUA_TNUMBER: | |
printf("%i (%i) = %g", i, i - (top + 1), lua_tonumber(L, i)); | |
break; | |
default: | |
printf("%i (%i) = %s", i, i - (top + 1), lua_typename(L, t)); | |
break; | |
} | |
printf("\n"); | |
} | |
printf("#### EOS ####\n"); | |
printf("\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment