From 8a910b9c9a62cd0016fc12e986442f273ff089b6 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Fri, 9 Aug 2013 20:28:59 +0200 Subject: Making our print function a bit smarter. --- src/BLua.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/BLua.cc b/src/BLua.cc index 4b34108..13b09cd 100644 --- a/src/BLua.cc +++ b/src/BLua.cc @@ -225,11 +225,21 @@ int Balau::LuaStatics::print(lua_State * __L) { int i; for (i = 1; i <= n; i++) { const char *s; - s = lua_tostring(__L, i); + if (lua_isstring(__L, i)) { + s = lua_tostring(__L, i); + } else { + L.getglobal("tostring"); + L.copy(i); + int r = lua_pcall(__L, 1, 1, 0); + s = lua_tostring(__L, -1); + if (r != 0) + s = NULL; + L.pop(); + } if (s == NULL) L.error("`tostring' must return a string to `print'"); if (i > 1) - Printer::print("\t"); + Printer::print(" "); Printer::print("%s", s); L.pop(); } -- cgit v1.2.3