1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- #ifndef _STACK_DUMP_H
- #define _STACK_DUMP_H
- #ifdef DEBUG
- #define STACK_DUMP(...) stack_dump (__VA_ARGS__)
- static void
- stack_dump (lua_State *L, const char *title)
- {
- // print out the scalar value or type of args on the stack
- int i;
- int top = lua_gettop(L); /* depth of the stack */
- printf("%20s : [", title);
- for (i = 1; i <= top; i++) { /* repeat for each level */
- int t = lua_type(L, i);
- switch (t)
- {
- case LUA_TNIL:
- {
- printf("nil");
- break;
- }
- case LUA_TBOOLEAN:
- {
- printf(lua_toboolean(L, i) ? "true" : "false");
- break;
- }
- case LUA_TLIGHTUSERDATA:
- {
- printf("lud@%p", lua_touserdata(L, i));
- break;
- }
- case LUA_TNUMBER:
- {
- printf("%g", lua_tonumber(L, i));
- break;
- }
- case LUA_TSTRING:
- {
- printf("'%s'", lua_tostring(L, i));
- break;
- }
- case LUA_TTABLE:
- {
- printf("{}");
- break;
- }
- case LUA_TFUNCTION:
- {
- printf("f@%p", lua_touserdata(L, i));
- break;
- }
- case LUA_TUSERDATA:
- {
- printf("ud(%p)", lua_touserdata(L, i));
- break;
- }
- case LUA_TTHREAD:
- {
- printf("Thrd(%p)", lua_touserdata(L, i));
- break;
- }
- default:
- { // other values
- printf("%s", lua_typename(L, t));
- break;
- }
- }
- if (i<top) printf(" "); /* put a separator */
- }
- printf("]\n"); /* end the listing */
- }
- #else
- #define STACK_DUMP(...)
- #endif // DEBUG
- #endif // _STACK_DUMP_H
|