Boolsheet avatar Boolsheet committed 7e5b88e

Try to reuse cmd if opened (on windows)

Comments (0)

Files changed (1)

 	}
 
 	lua_setfield(L, -2, "_version_compat");
-	
+
 #ifdef LOVE_WINDOWS
 	lua_pushstring(L, "Windows");
 #elif defined(LOVE_MACOSX)
 	if (is_open)
 		return 0;
 
+	is_open = true;
+
 	static const int MAX_CONSOLE_LINES = 5000;
 	long std_handle;
 	int console_handle;
 	CONSOLE_SCREEN_BUFFER_INFO console_info;
 	FILE *fp;
 
-	AllocConsole();
+	/* Legendary AttachConsole bug workaround.
+	 * AttachConsole breaks console allocation completely if it fails.
+	 * Let's check through the environment variable PROMPT if love was
+	 * started with cmd.exe.
+	*/
+	if (GetEnvironmentVariable(TEXT("PROMPT"), NULL, 0) != 0)
+	{
+		if (AttachConsole(ATTACH_PARENT_PROCESS) == 0)
+			return 0;
+	}
+	else
+	{
+		if (AllocConsole() == 0)
+			return 0;
+	}
 
 	// Set size.
 	GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &console_info);
 	// Sync std::cout, std::cerr, etc.
 	std::ios::sync_with_stdio();
 
-	is_open = true;
-
 	return 0;
 }
 
 	// Oh, you just want the version? Okay!
 	if (argc > 1 && strcmp(argv[1],"--version") == 0)
 	{
+#ifdef LOVE_LEGENDARY_CONSOLE_IO_HACK
+		w__openConsole(NULL);
+#endif // LOVE_LEGENDARY_CONSOLE_IO_HACK
 		printf("LOVE %s (%s)\n", love::VERSION, love::VERSION_CODENAME);
 		return 0;
 	}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.