From 81e63f75c0bce2b94c38ffe58781cd38997c8650 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 9 Feb 2001 17:52:24 -0200 Subject: `tostring' uses type names (when available) --- lbaselib.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lbaselib.c') diff --git a/lbaselib.c b/lbaselib.c index 0599d08b..93ddc2ac 100644 --- a/lbaselib.c +++ b/lbaselib.c @@ -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 ** See Copyright Notice in lua.h */ @@ -345,14 +345,19 @@ static int luaB_tostring (lua_State *L) { lua_pushvalue(L, 1); return 1; case LUA_TTABLE: - sprintf(buff, "table: %p", lua_topointer(L, 1)); + sprintf(buff, "%.40s: %p", lua_xtype(L, 1), lua_topointer(L, 1)); break; case LUA_TFUNCTION: sprintf(buff, "function: %p", lua_topointer(L, 1)); break; - case LUA_TUSERDATA: - sprintf(buff, "userdata(%d): %p", lua_tag(L, 1), lua_touserdata(L, 1)); + case LUA_TUSERDATA: { + 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; + } case LUA_TNIL: lua_pushliteral(L, "nil"); return 1; -- cgit v1.2.3-55-g6feb