diff --git a/src/love.cpp b/src/love.cpp index 6324a7c40..d3d8e2bf8 100644 --- a/src/love.cpp +++ b/src/love.cpp @@ -44,14 +44,6 @@ extern "C" { #include "common/ios.h" #endif -#ifdef LOVE_ANDROID -#include "common/android.h" -extern "C" -{ -#include "luajit.h" -} -#endif - #ifdef LOVE_WINDOWS extern "C" { @@ -140,39 +132,6 @@ static int love_preload(lua_State *L, lua_CFunction f, const char *name) return 0; } -#ifdef LOVE_ANDROID -static int l_print_sdl_log(lua_State *L) -{ - int nargs = lua_gettop(L); - - lua_getglobal(L, "tostring"); - - std::string outstring; - - for (int i = 1; i <= nargs; i++) - { - // Call tostring(arg) and leave the result on the top of the stack. - lua_pushvalue(L, -1); - lua_pushvalue(L, i); - lua_call(L, 1, 1); - - const char *s = lua_tostring(L, -1); - if (s == nullptr) - return luaL_error(L, "'tostring' must return a string to 'print'"); - - if (i > 1) - outstring += "\t"; - - outstring += s; - - lua_pop(L, 1); // Pop the result of tostring(arg). - } - - SDL_Log("[LOVE] %s", outstring.c_str()); - return 0; -} -#endif - enum DoneAction { DONE_QUIT, @@ -201,11 +160,6 @@ static DoneAction runlove(int argc, char **argv, int &retval) lua_State *L = luaL_newstate(); luaL_openlibs(L); -#ifdef LOVE_ANDROID - luaJIT_setmode(L, 0, LUAJIT_MODE_ENGINE| LUAJIT_MODE_OFF); - lua_register(L, "print", l_print_sdl_log); -#endif - // Add love to package.preload for easy requiring. love_preload(L, luaopen_love, "love"); @@ -257,9 +211,7 @@ static DoneAction runlove(int argc, char **argv, int &retval) lua_pushvalue(L, -2); int stackpos = lua_gettop(L); while (lua_resume(L, 0) == LUA_YIELD) - { lua_pop(L, lua_gettop(L) - stackpos); - } retval = 0; DoneAction done = DONE_QUIT; diff --git a/src/modules/love/love.cpp b/src/modules/love/love.cpp index da8bb2618..ee40fa5db 100644 --- a/src/modules/love/love.cpp +++ b/src/modules/love/love.cpp @@ -34,6 +34,14 @@ #include #endif // LOVE_WINDOWS +#ifdef LOVE_ANDROID +#include +extern "C" +{ +#include "luajit.h" +} +#endif // LOVE_ANDROID + #ifdef LOVE_LEGENDARY_CONSOLE_IO_HACK #include #include @@ -202,6 +210,39 @@ int w__openConsole(lua_State *L); int w__setAccelerometerAsJoystick(lua_State *L); #endif +#ifdef LOVE_ANDROID +static int w_print_sdl_log(lua_State *L) +{ + int nargs = lua_gettop(L); + + lua_getglobal(L, "tostring"); + + std::string outstring; + + for (int i = 1; i <= nargs; i++) + { + // Call tostring(arg) and leave the result on the top of the stack. + lua_pushvalue(L, -1); + lua_pushvalue(L, i); + lua_call(L, 1, 1); + + const char *s = lua_tostring(L, -1); + if (s == nullptr) + return luaL_error(L, "'tostring' must return a string to 'print'"); + + if (i > 1) + outstring += "\t"; + + outstring += s; + + lua_pop(L, 1); // Pop the result of tostring(arg). + } + + SDL_Log("[LOVE] %s", outstring.c_str()); + return 0; +} +#endif + const char *love_version() { // Do not refer to love::VERSION here, the linker @@ -303,6 +344,11 @@ int luaopen_love(lua_State *L) lua_pushstring(L, love::VERSION_CODENAME); lua_setfield(L, -2, "_version_codename"); +#ifdef LOVE_ANDROID + luaJIT_setmode(L, 0, LUAJIT_MODE_ENGINE | LUAJIT_MODE_OFF); + lua_register(L, "print", w_print_sdl_log); +#endif + #ifdef LOVE_LEGENDARY_CONSOLE_IO_HACK lua_pushcfunction(L, w__openConsole); lua_setfield(L, -2, "_openConsole");