From 9bdc1ce0c516f6706e580770d9016b60b7a6e1ab Mon Sep 17 00:00:00 2001 From: pixel Date: Sun, 18 May 2008 21:41:33 +0000 Subject: Fixing tostring to have a more coherent behavior. --- lib/BLua.cc | 16 ++++++++++------ 1 file 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 #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 : "", l); -- cgit v1.2.3