From 8f20cb7cc523ce1986acbe07b0f98b7b25154028 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Mon, 18 Aug 2014 16:23:39 +0200 Subject: [PATCH] added print redirect to SDL_Log (fixes #40) --- jni/love/src/love.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/jni/love/src/love.cpp b/jni/love/src/love.cpp index 5662ac62..121241d2 100644 --- a/jni/love/src/love.cpp +++ b/jni/love/src/love.cpp @@ -38,6 +38,8 @@ extern "C" { #include "OSX.h" #endif // LOVE_MACOSX +#include + #ifdef LOVE_LEGENDARY_UTF8_ARGV_HACK void get_utf8_arguments(int &argc, char **&argv) @@ -133,22 +135,22 @@ static int love_preload(lua_State *L, lua_CFunction f, const char *name) return 0; } -static int l_sdl_log(lua_State *L) { - if ((lua_gettop(L) != 1) || !lua_isstring(L, -1)) { - SDL_Log ("[LöveSDL] invalid error message: expected string"); +static int l_print_sdl_log (lua_State *L) { + int nargs = lua_gettop(L); + + if (nargs == 0) return 0; + + std::string out_string = lua_tostring (L, 1); + for (int i = 2; i <= nargs; i++) { + out_string += "\t"; + out_string += lua_tostring (L, i); } - SDL_Log ("[LöveSDL] %s", lua_tostring(L, -1)); - + SDL_Log ("[LOVE2D] %s", out_string.c_str()); return 0; } -static const struct luaL_Reg sdl_lib[] = { - {"log", l_sdl_log}, - {NULL, NULL} -}; - int main(int argc, char **argv) { #ifdef LOVE_ANDROID @@ -181,7 +183,9 @@ int main(int argc, char **argv) lua_State *L = luaL_newstate(); luaL_openlibs(L); - luaL_register (L, "SDL", sdl_lib); +#ifdef LOVE_ANDROID + lua_register (L, "print", l_print_sdl_log); +#endif // Add love to package.preload for easy requiring. love_preload(L, luaopen_love, "love");