new function luaL_tostring

This commit is contained in:
Roberto Ierusalimschy
2007-02-07 15:51:21 -02:00
parent 92dc64e121
commit cf86576a83
3 changed files with 30 additions and 22 deletions

View File

@@ -1,5 +1,5 @@
/*
** $Id: lbaselib.c,v 1.194 2006/10/20 19:30:53 roberto Exp roberto $
** $Id: lbaselib.c,v 1.195 2006/10/24 19:46:12 roberto Exp roberto $
** Basic library
** See Copyright Notice in lua.h
*/
@@ -396,25 +396,7 @@ static int luaB_xpcall (lua_State *L) {
static int luaB_tostring (lua_State *L) {
luaL_checkany(L, 1);
if (luaL_callmeta(L, 1, "__tostring")) /* is there a metafield? */
return 1; /* use its value */
switch (lua_type(L, 1)) {
case LUA_TNUMBER:
lua_pushstring(L, lua_tostring(L, 1));
break;
case LUA_TSTRING:
lua_pushvalue(L, 1);
break;
case LUA_TBOOLEAN:
lua_pushstring(L, (lua_toboolean(L, 1) ? "true" : "false"));
break;
case LUA_TNIL:
lua_pushliteral(L, "nil");
break;
default:
lua_pushfstring(L, "%s: %p", luaL_typename(L, 1), lua_topointer(L, 1));
break;
}
luaL_tostring(L, 1);
return 1;
}