diff options
author | Kahrl <kahrl@gmx.net> | 2013-06-21 00:04:18 +0200 |
---|---|---|
committer | Kahrl <kahrl@gmx.net> | 2013-06-21 00:04:18 +0200 |
commit | c2cdaceed0d43317d8e8d431052854fe72d8fddf (patch) | |
tree | 851607d43d6871a6a4d64085d1d9b727b2f56d16 /src/script/lua_api | |
parent | 469d0b120e3d06c4c3a0079e71215d744339ec48 (diff) | |
download | minetest-c2cdaceed0d43317d8e8d431052854fe72d8fddf.tar.gz minetest-c2cdaceed0d43317d8e8d431052854fe72d8fddf.tar.bz2 minetest-c2cdaceed0d43317d8e8d431052854fe72d8fddf.zip |
Make minetest.debug accept multiple parameters; convert them to string
Diffstat (limited to 'src/script/lua_api')
-rw-r--r-- | src/script/lua_api/luaapi.cpp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/script/lua_api/luaapi.cpp b/src/script/lua_api/luaapi.cpp index 667a3afcf..e19c90952 100644 --- a/src/script/lua_api/luaapi.cpp +++ b/src/script/lua_api/luaapi.cpp @@ -105,13 +105,31 @@ bool ModApiBasic::Initialize(lua_State* L,int top) { return retval; } -// debug(text) +// debug(...) // Writes a line to dstream int ModApiBasic::l_debug(lua_State *L) { NO_MAP_LOCK_REQUIRED; - std::string text = lua_tostring(L, 1); - dstream << text << std::endl; + // Handle multiple parameters to behave like standard lua print() + int n = lua_gettop(L); + lua_getglobal(L, "tostring"); + for(int i = 1; i <= n; i++){ + /* + Call tostring(i-th argument). + This is what print() does, and it behaves a bit + differently from directly calling lua_tostring. + */ + lua_pushvalue(L, -1); /* function to be called */ + lua_pushvalue(L, i); /* value to print */ + lua_call(L, 1, 1); + const char *s = lua_tostring(L, -1); + if(i>1) + dstream << "\t"; + if(s) + dstream << s; + lua_pop(L, 1); + } + dstream << std::endl; return 0; } |