Lua 查看栈的宏

#ifndef SHOW_STACK
#define SHOW_STACK(stack) {\
int show_stack_n = lua_gettop(stack), show_stack_i;\
printf(" _____________________STACK_____________________\n");\
for(show_stack_i=show_stack_n;show_stack_i>0;--show_stack_i)\
switch(lua_type(L, show_stack_i)) {\
case LUA_TNIL:\
printf("|\t%d / %d IS A LUA_TNIL\n", show_stack_i, show_stack_n);\
break;\
case LUA_TNUMBER:\
printf("|\t%d / %d IS A LUA_TNUMBER\n", show_stack_i, show_stack_n);\
break;\
case LUA_TBOOLEAN:\
printf("|\t%d / %d IS A LUA_TBOOLEAN\n", show_stack_i, show_stack_n);\
break;\
case LUA_TSTRING:\
printf("|\t%d / %d IS A LUA_TSTRING\n", show_stack_i, show_stack_n);\
break;\
case LUA_TTABLE:\
printf("|\t%d / %d IS A LUA_TTABLE\n", show_stack_i, show_stack_n);\
break;\
case LUA_TFUNCTION:\
printf("|\t%d / %d IS A LUA_TFUNCTION\n", show_stack_i, show_stack_n);\
break;\
case LUA_TUSERDATA:\
printf("|\t%d / %d IS A LUA_TUSERDATA\n", show_stack_i, show_stack_n);\
break;\
case LUA_TTHREAD:\
printf("|\t%d / %d IS A LUA_TTHREAD\n", show_stack_i, show_stack_n);\
break;\
case LUA_TLIGHTUSERDATA:\
printf("|\t%d / %d IS A LUA_TLIGHTUSERDATA\n", show_stack_i, show_stack_n);\
break;\
default:\
printf("|\t%d / %d IS A UNKNOWN\n", show_stack_i, show_stack_n);\
break;}}
#endif // SHOW_STACK


#ifndef EXPAND_TABLE
#define EXPAND_TABLE(stack) do{\
printf(" _____________________TABLE_____________________\n");\
if(!lua_gettop(stack)) {\
printf("|\tSTACK IS EMPTY\n");break;}\
int stack_table_idx = lua_gettop(stack);\
if(!lua_istable(stack, stack_table_idx)){\
printf("|\tSTACK TOP IS NOT TABLE\n");break;}\
lua_pushnil(stack);\
while (lua_next(stack, stack_table_idx)!=0){\
printf("|%20s\t", lua_tostring(stack, -2));\
switch(lua_type(L, -1)) {\
case LUA_TNIL:\
printf("LUA_TNIL\n");\
break;\
case LUA_TNUMBER:\
printf("LUA_TNUMBER\n");\
break;\
case LUA_TBOOLEAN:\
printf("LUA_TBOOLEAN\n");\
break;\
case LUA_TSTRING:\
printf("LUA_TSTRING\n");\
break;\
case LUA_TTABLE:\
printf("LUA_TTABLE\n");\
break;\
case LUA_TFUNCTION:\
printf("LUA_TFUNCTION\n");\
break;\
case LUA_TUSERDATA:\
printf("LUA_TUSERDATA\n");\
break;\
case LUA_TTHREAD:\
printf("LUA_TTHREAD\n");\
break;\
case LUA_TLIGHTUSERDATA:\
printf("LUA_TLIGHTUSERDATA\n");\
break;\
default:\
printf("UNKNOWN\n");\
break;}lua_pop(L, 1);\
}}while(0);
#endif // EXPAND_TABLE

 

posted on 2013-10-18 20:11  盐味  阅读(902)  评论(0编辑  收藏  举报