lua-users home
lua-l archive

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


Sorry about that.  Seems the code I posted has a mixture of styles in
it.  One uses printf to print to stdout, the other prints to wherever
Lua's print() goes to which is different for me sometimes.   Don't use
the code the way I posted it. Pick one or the other.

wes

On 8/16/07, Wesley Smith <wesley.hoke@gmail.com> wrote:
> I would highly recommend picking up programming in Lua.  It has all
> kind of stuff in there like this.  You will learn Lua much faster!
>
> int stackDump(lua_State *L)
> {
>         int i;
>         int top = lua_gettop(L);
>
>         printf("stack dump %d:\n", top);
>         for(i=top; i >= 1; i--) {
>                 int t = lua_type(L, i);
>
>                 switch(t)
>                 {
>                         case LUA_TSTRING:
>                                         printf("%d \t'%s' string\n", i, lua_tostring(L, i));
>                                         break;
>
>                         case LUA_TBOOLEAN:
>                                         printf(lua_toboolean(L, i) ? "\ttrue\n" : "\tfalse\n");
>                                         break;
>
>                         case LUA_TNUMBER:
>                                         printf("%d \t'%f' number\n", i, lua_tonumber(L, i));
>                                         break;
>
>                         case LUA_TLIGHTUSERDATA:
>                                         printf("%d \t'%x'\n", i, lua_touserdata(L, i));
>                                         break;
>
>                         case LUA_TUSERDATA:
>                                         printf("%d ", i);
>                                         lua_getglobal(L, "print");
>                                         lua_pushvalue(L, i);
>                                         lua_call(L, 1, 0);
>                                         //printf("%d \t'%x %s'\n", i, lua_touserdata(L, i), T::name);
>                                         break;
>
>                         case LUA_TFUNCTION:
>                                         printf("%d \t'func: %x'\n", i, lua_tocfunction(L, i));
>                                         break;
>
>                         case LUA_TTABLE:
>                                         printf("%d ", i);
>                                         lua_getglobal(L, "print");
>                                         lua_pushvalue(L, i);
>                                         lua_call(L, 1, 0);
>                                         break;
>
>                         default:
>                                         printf("%d \t'%s'\n", i, lua_typename(L, t));
>                                         break;
>                 }
>         }
>
>         return 0;
> }
>