Skip to content

Instantly share code, notes, and snippets.

@leodido
Created September 23, 2019 18:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leodido/ee40e3ad09a13bcc91af5407d9e69204 to your computer and use it in GitHub Desktop.
Save leodido/ee40e3ad09a13bcc91af5407d9e69204 to your computer and use it in GitHub Desktop.
Dump the Lua stack
/*
* 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