lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Le 27 juil. 2010 à 13:30, Luiz Henrique de Figueiredo a écrit :

>> Could someone points out some tricks or tools to be able to explore the Lua stack from C code ?
> 
> See this thread:
> 	http://lua-users.org/lists/lua-l/2009-01/msg00140.html


Great !
Thanks.

As the macro was for C++, here is the equivalent for C :


#define showstack(lstack, infos)	\
fprintf( stderr, "\nShowStack -- %s\n", infos  );\
for (int i=0;i<lua_gettop(lstack)+1;i+=1)\
{\
if (lua_isnumber(lstack,i))\
{\
fprintf( stderr, "%2d: number : %d\n", i, (int)lua_tonumber(lstack,i) );\
}\
else if (lua_isstring(lstack,i))\
{\
fprintf( stderr, "%2d: string : %s\n", i, lua_tostring(lstack,i) );\
}\
else if (lua_istable(lstack,i))\
{\
fprintf( stderr, "%2d: table\n", i );\
}\
else if (lua_iscfunction(lstack,i))\
{\
fprintf( stderr, "%2d: cfunction\n", i  );\
}\
else if (lua_isfunction(lstack,i))\
{\
fprintf( stderr, "%2d: function\n", i  );\
}\
else if (lua_isboolean(lstack,i))\
{\
if (lua_toboolean(lstack,i)== True)\
fprintf( stderr, "%2d: boolean : true\n", i  );\
else\
fprintf( stderr, "%2d: boolean : false\n", i  );\
}\
else if (lua_isuserdata(lstack,i))\
{\
fprintf( stderr, "%2d: userdata\n", i  );\
}\
else if (lua_isnil(lstack,i))\
{\
fprintf( stderr, "%2d: nil\n", i  );\
}\
else if (lua_islightuserdata(lstack,i))\
{\
fprintf( stderr, "%2d: light userdata\n", i  );\
}\
}