lua-users home
lua-l archive

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


>  static void stackprint(lua_State *L, int from) {
>    int top=lua_gettop(L);
>    printf("Stack:");
>    while (from<=top) {
>      printf(" %s",luaL_tolstring(L,from++,NULL));
>      lua_pop(L,1); }
>    printf("\n");
> }

Using luaL_tolstring will change the type of number values to string.

I use this:

static void dumpstack (lua_State *L, const char *message) {
  int top=lua_gettop(L);
  int i;
  printf("dumpstack -- %s\n",message);
  for (i=1; i<=top; i++) {
    printf("%d\t%s\t",i,luaL_typename(L,i));
    switch (lua_type(L, i)) {
      case LUA_TNUMBER:
        printf("%g\n",lua_tonumber(L,i));
        break;
      case LUA_TSTRING:
        printf("%s\n",lua_tostring(L,i));
        break;
      case LUA_TBOOLEAN:
        printf("%s\n", (lua_toboolean(L, i) ? "true" : "false"));
        break;
      case LUA_TNIL:
        printf("%s\n", "nil");
        break;
      default:
        printf("%p\n",lua_topointer(L,i));
        break;
    }
  }
  printf("dumpstack -- END\n");
}