Lua stack Dump for C + +

Source: Internet
Author: User

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)
02 {
03     inti;
04     inttop = lua_gettop(l);
05
06     printf("total in stack %d/n",top);
07
08     for(i = 1; i <= top; i++)
09     {  /* repeat for each level */
10         intt = lua_type(l, i);
11         switch(t) {
12             caseLUA_TSTRING:  /* strings */
13                 printf("string: ‘%s‘/n", lua_tostring(l, i));
14                 break;
15             caseLUA_TBOOLEAN:  /* booleans */
16                 printf("boolean %s/n",lua_toboolean(l, i) ? "true":"false");
17                 break;
18             caseLUA_TNUMBER:  /* numbers */
19                 printf("number: %g/n", lua_tonumber(l, i));
20                 break;
21             default:  /* other values */
22                 printf("%s/n", lua_typename(l, t));
23                 break;
24         }
25         printf("  ");  /* put a separator */
26     }
27     printf("/n");  /* end the listing */
28 }

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 + +

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.