diff options
author | pixel <pixel> | 2006-02-09 16:57:30 +0000 |
---|---|---|
committer | pixel <pixel> | 2006-02-09 16:57:30 +0000 |
commit | 16c41f2f9f1d86d861254ef54becbd2bd728f848 (patch) | |
tree | af2cd9c9be284de1dc2f70c6fd27568781ddfad3 /lib | |
parent | 20c5645237551095ae6b7b4dc8720b9262e74c8e (diff) |
Changing the behavior of tostring: now booleans and nils can be converted to strings.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lua/src/lvm.c | 22 |
1 files changed, 21 insertions, 1 deletions
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 } |