From 9f4987f4f821906cb3458fce1989d51d7710eae2 Mon Sep 17 00:00:00 2001 From: fysx Date: Fri, 6 Dec 2013 16:04:25 +0100 Subject: [PATCH] added SDL.log() to enable logging from Lua --- jni/love/src/love.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/jni/love/src/love.cpp b/jni/love/src/love.cpp index f0a26cc1..026dbb9d 100644 --- a/jni/love/src/love.cpp +++ b/jni/love/src/love.cpp @@ -134,12 +134,27 @@ 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"); + return 0; + } + + SDL_Log ("[LöveSDL] %s", lua_tostring(L, -1)); + + return 0; +} + +static const struct luaL_Reg sdl_lib[] = { + {"log", l_sdl_log}, + {NULL, NULL} +}; + int main(int argc, char **argv) { + SDL_SetHint("LOVE_GRAPHICS_USE_OPENGLES", "1"); - SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE); - SDL_Log ("Hello from love main"); - + SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE); #ifdef LOVE_LEGENDARY_UTF8_ARGV_HACK int hack_argc = 0; char **hack_argv = 0; @@ -167,6 +182,8 @@ int main(int argc, char **argv) lua_State *L = luaL_newstate(); luaL_openlibs(L); + luaL_register (L, "SDL", sdl_lib); + // Add love to package.preload for easy requiring. love_preload(L, luaopen_love, "love");