`tostring' uses type names (when available)

This commit is contained in:
Roberto Ierusalimschy 2001-02-09 17:52:24 -02:00
parent c81404cae5
commit 81e63f75c0
1 changed files with 9 additions and 4 deletions

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lbaselib.c,v 1.21 2001/02/02 19:02:40 roberto Exp roberto $ ** $Id: lbaselib.c,v 1.22 2001/02/06 13:59:29 roberto Exp roberto $
** Basic library ** Basic library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -345,14 +345,19 @@ static int luaB_tostring (lua_State *L) {
lua_pushvalue(L, 1); lua_pushvalue(L, 1);
return 1; return 1;
case LUA_TTABLE: case LUA_TTABLE:
sprintf(buff, "table: %p", lua_topointer(L, 1)); sprintf(buff, "%.40s: %p", lua_xtype(L, 1), lua_topointer(L, 1));
break; break;
case LUA_TFUNCTION: case LUA_TFUNCTION:
sprintf(buff, "function: %p", lua_topointer(L, 1)); sprintf(buff, "function: %p", lua_topointer(L, 1));
break; break;
case LUA_TUSERDATA: case LUA_TUSERDATA: {
sprintf(buff, "userdata(%d): %p", lua_tag(L, 1), lua_touserdata(L, 1)); const char *t = lua_xtype(L, 1);
if (strcmp(t, "userdata") == 0)
sprintf(buff, "userdata(%d): %p", lua_tag(L, 1), lua_touserdata(L, 1));
else
sprintf(buff, "%.40s: %p", t, lua_touserdata(L, 1));
break; break;
}
case LUA_TNIL: case LUA_TNIL:
lua_pushliteral(L, "nil"); lua_pushliteral(L, "nil");
return 1; return 1;