http://blog.csdn.net/cnjet/article/details/5909567
Any interactions between C + + and Lua are going through LUA stacks. Aware of the stack status may help for debugging. I always does that, would a peek of the current Lua stack not only helps me debug my codes but also helps me figure out the W Ays how I can pass table from C + + to Lua and vice versa.
01 |
voidstackdump_g(lua_State* l) |
04 |
inttop = lua_gettop(l); |
06 |
printf("total in stack %d/n",top); |
08 |
for(i = 1; i <= top; i++) |
09 |
{ /* repeat for each level */ |
10 |
intt = lua_type(l, i); |
12 |
caseLUA_TSTRING: /* strings */ |
13 |
printf("string: ‘%s‘/n", lua_tostring(l, i)); |
15 |
caseLUA_TBOOLEAN: /* booleans */ |
16 |
printf("boolean %s/n",lua_toboolean(l, i) ? "true":"false"); |
18 |
caseLUA_TNUMBER: /* numbers */ |
19 |
printf("number: %g/n", lua_tonumber(l, i)); |
21 |
default: /* other values */ |
22 |
printf("%s/n", lua_typename(l, t)); |
25 |
printf(" "); /* put a separator */ |
27 |
printf("/n"); /* end the listing */ |
I usually interested on knowing what many blocks in my stack had been occupied and also each block ' s variable type, if they is string, number or bool, I would like to know the value as well.
The usage is simple and you'll only have needs to pass in your current LUA state pointer.
The print line output could look like this:
total in stack 2string: ‘5A5B5C8855778899‘ number: 89
Lua stack Dump for C + +