标签:
http://blog.csdn.net/cnjet/article/details/5909567
Any interactions between c++ and lua are going through lua stack. Aware of the stack status may help for debugging. I always do that, will a peek of the current Lua stack not only helps me debug my codes but also helps me figure out the ways how I can pass table from c++ to Lua and vice versa.
01 |
void stackdump_g(lua_State* l) |
04 |
int top = lua_gettop(l); |
06 |
printf ( "total in stack %d/n" ,top); |
08 |
for (i = 1; i <= top; i++) |
10 |
int t = lua_type(l, i); |
13 |
printf ( "string: ‘%s‘/n" , lua_tostring(l, i)); |
16 |
printf ( "boolean %s/n" ,lua_toboolean(l, i) ? "true" : "false" ); |
19 |
printf ( "number: %g/n" , lua_tonumber(l, i)); |
22 |
printf ( "%s/n" , lua_typename(l, t)); |
I usually interested on knowing how many blocks in my stack had been occupied and also each block’s variable type, if they are string, number or bool, I would like to know the value as well.
The usage is simple, you will only needs to pass in your current Lua State pointer.
The print line output may look like this:
total in stack 2
string: ‘5A5B5C8855778899‘
number: 89
Lua stack dump for c++
标签:
原文地址:http://www.cnblogs.com/gamekk/p/4779910.html