From 16c41f2f9f1d86d861254ef54becbd2bd728f848 Mon Sep 17 00:00:00 2001 From: pixel Date: Thu, 9 Feb 2006 16:57:30 +0000 Subject: Changing the behavior of tostring: now booleans and nils can be converted to strings. --- lib/lua/src/lvm.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/lua/src/lvm.c b/lib/lua/src/lvm.c index 7334edc..5c6620a 100644 --- a/lib/lua/src/lvm.c +++ b/lib/lua/src/lvm.c @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 1.8 2005-02-12 22:57:53 pixel Exp $ +** $Id: lvm.c,v 1.9 2006-02-09 16:57:30 pixel Exp $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -53,6 +53,7 @@ const TObject *luaV_tonumber (const TObject *obj, TObject *n) { int luaV_tostring (lua_State *L, StkId obj) { +#if 0 if (!ttisnumber(obj)) return 0; else { @@ -61,6 +62,25 @@ int luaV_tostring (lua_State *L, StkId obj) { setsvalue2s(obj, luaS_new(L, s)); return 1; } +#else + if (ttisnumber(obj)) { + char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */ + lua_number2str(s, nvalue(obj)); + setsvalue2s(obj, luaS_new(L, s)); + return 1; + } else if (ttisboolean(obj)) { + if (bvalue(obj)) + setsvalue2s(obj, luaS_new(L, "(true)")) + else + setsvalue2s(obj, luaS_new(L, "(false)")); + return 1; + } else if (ttisnil(obj)) { + setsvalue(obj, luaS_new(L, "(nil)")); + return 1; + } else { + return 0; + } +#endif } -- cgit v1.2.3