From f66753fec271a82de107b8c42a8fb149a6fe8175 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 6 Jan 2018 00:59:09 -0400 Subject: [PATCH] Windows: redirect stdout to the parent command prompt when love.exe --version is run. --- src/love.cpp | 4 ++++ src/modules/love/love.cpp | 44 ++++++++++++++++++++++++++------------- src/modules/love/love.h | 4 ++++ 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/love.cpp b/src/love.cpp index 2c9c72428..a4a2444c6 100644 --- a/src/love.cpp +++ b/src/love.cpp @@ -151,6 +151,10 @@ static DoneAction runlove(int argc, char **argv, int &retval) // Oh, you just want the version? Okay! if (argc > 1 && strcmp(argv[1], "--version") == 0) { +#ifdef LOVE_LEGENDARY_CONSOLE_IO_HACK + const char *err = nullptr; + love_openConsole(err); +#endif printf("LOVE %s (%s)\n", love_version(), love_codename()); retval = 0; return DONE_QUIT; diff --git a/src/modules/love/love.cpp b/src/modules/love/love.cpp index 0af91c9cc..14a6756f6 100644 --- a/src/modules/love/love.cpp +++ b/src/modules/love/love.cpp @@ -455,15 +455,13 @@ static bool IsWindowsVistaOrGreater() return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, mask) != FALSE; } -int w__openConsole(lua_State *L) +bool love_openConsole(const char *&err) { static bool is_open = false; + err = nullptr; if (is_open) - { - love::luax_pushboolean(L, is_open); - return 1; - } + return true; is_open = true; @@ -476,8 +474,8 @@ int w__openConsole(lua_State *L) if (!AllocConsole()) { is_open = false; - love::luax_pushboolean(L, is_open); - return 1; + err = "Could not create console."; + return is_open; } SetConsoleTitle(TEXT("LOVE Console")); @@ -495,20 +493,38 @@ int w__openConsole(lua_State *L) // Redirect stdout. fp = freopen("CONOUT$", "w", stdout); - if (L && fp == NULL) - return luaL_error(L, "Console redirection of stdout failed."); + if (fp == NULL) + { + err = "Console redirection of stdout failed."; + return is_open; + } // Redirect stdin. fp = freopen("CONIN$", "r", stdin); - if (L && fp == NULL) - return luaL_error(L, "Console redirection of stdin failed."); + if (fp == NULL) + { + err = "Console redirection of stdin failed."; + return is_open; + } // Redirect stderr. fp = freopen("CONOUT$", "w", stderr); - if (L && fp == NULL) - return luaL_error(L, "Console redirection of stderr failed."); + if (fp == NULL) + { + err = "Console redirection of stderr failed."; + return is_open; + } - love::luax_pushboolean(L, is_open); + return is_open; +} + +int w__openConsole(lua_State *L) +{ + const char *err = nullptr; + bool isopen = love_openConsole(err); + if (err != nullptr) + return luaL_error(L, err); + love::luax_pushboolean(L, isopen); return 1; } diff --git a/src/modules/love/love.h b/src/modules/love/love.h index 06da3cabe..9458366ec 100644 --- a/src/modules/love/love.h +++ b/src/modules/love/love.h @@ -38,6 +38,10 @@ LOVE_EXPORT int luaopen_love(lua_State *L); LOVE_EXPORT int luaopen_love_nogame(lua_State *L); LOVE_EXPORT int luaopen_love_boot(lua_State *L); +#ifdef LOVE_LEGENDARY_CONSOLE_IO_HACK +LOVE_EXPORT bool love_openConsole(const char *&err); +#endif + #ifdef __cplusplus } #endif