diff options
author | pixel <pixel> | 2008-05-18 21:41:33 +0000 |
---|---|---|
committer | pixel <pixel> | 2008-05-18 21:41:33 +0000 |
commit | 9bdc1ce0c516f6706e580770d9016b60b7a6e1ab (patch) | |
tree | 7d79351e4d17a70f18f51f0cfce93cff1fec9ad7 | |
parent | 073ef91d7b0554bbebbde4394094f27c2792541d (diff) |
Fixing tostring to have a more coherent behavior.
-rw-r--r-- | lib/BLua.cc | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/BLua.cc b/lib/BLua.cc index 1db9dda..bc465f3 100644 --- a/lib/BLua.cc +++ b/lib/BLua.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: BLua.cc,v 1.58 2008-01-25 10:09:19 pixel Exp $ */ +/* $Id: BLua.cc,v 1.59 2008-05-18 21:41:33 pixel Exp $ */ #include <stdlib.h> #include "BLua.h" @@ -790,13 +790,17 @@ lua_Number Lua::tonumber(int i) { String Lua::tostring(int i) { const char * r = 0; size_t l = -1; - if (isnil(i)) { - r = "(nil)"; - } else if (isboolean(i)) { + switch (type(i)) { + case LUA_TNIL: + r = "(nil)"; + break; + case LUA_TBOOLEAN: r = toboolean(i) ? "true" : "false"; - } else if (isnumber(i)) { + break; + case LUA_TNUMBER: return String(tonumber(i)); - } else { + break; + default: r = lua_tolstring(L, i, &l); } return String(r ? r : "<lua-NULL>", l); |