mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Windows: redirect stdout to the parent command prompt when love.exe --version is run.
This commit is contained in:
@@ -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;
|
||||
|
||||
+30
-14
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user