Skip to content

Instantly share code, notes, and snippets.

@yorung
Created February 9, 2015 00:05
Show Gist options
  • Save yorung/6b51703f4d7fddf72039 to your computer and use it in GitHub Desktop.
Save yorung/6b51703f4d7fddf72039 to your computer and use it in GitHub Desktop.
Lua stack dump (wrong! numbers on the Lua stack will be replaced with string)
void _dumpStack(lua_State* L, const char* func, int line)
{
int top = lua_gettop(L);
printf("(%s,%d) top=%d\n", func, line, top);
for (int i = 0; i < top; i++) {
int positive = top - i;
int negative = -(i + 1);
int type = lua_type(L, positive);
const char* typeName = lua_typename(L, type);
const char* value = lua_tostring(L, positive); // danger!!! numbers on the Lua stack will be replaced with string
printf("%d/%d: type=%s value=%s\n", positive, negative, typeName, value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment