lua-users home
lua-l archive

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


Here's another version, based on code from PiL:
	http://www.lua.org/pil/24.2.3.html

static void dumpstack (lua_State *L, const char *message) {
  int i;
  int top=lua_gettop(L);
  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");
}