summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-08-09 20:28:59 +0200
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-08-09 20:28:59 +0200
commit8a910b9c9a62cd0016fc12e986442f273ff089b6 (patch)
tree6bfbeaba0e373acea69dc0509e21e42cab2118c3
parente5001bd5fc52a039a340b214e736a23fed07c6b2 (diff)
Making our print function a bit smarter.
-rw-r--r--src/BLua.cc14
1 files 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();
}