diff --git a/platform/msvc2010/liblove.vcxproj b/platform/msvc2010/liblove.vcxproj index 6b24e3f0d..824bdb221 100644 --- a/platform/msvc2010/liblove.vcxproj +++ b/platform/msvc2010/liblove.vcxproj @@ -364,7 +364,6 @@ - @@ -428,6 +427,7 @@ + @@ -655,6 +655,7 @@ + diff --git a/platform/msvc2010/liblove.vcxproj.filters b/platform/msvc2010/liblove.vcxproj.filters index 6a3853f70..4dfb51d48 100644 --- a/platform/msvc2010/liblove.vcxproj.filters +++ b/platform/msvc2010/liblove.vcxproj.filters @@ -130,9 +130,11 @@ {d46cbbf1-a76f-4401-83d4-1f20492f9889} + + {5fb201c1-9b39-48ca-8334-6862da260b43} + - common @@ -733,6 +735,9 @@ modules\window\sdl + + modules\love + @@ -1412,6 +1417,9 @@ modules\window\sdl + + modules\love + diff --git a/platform/msvc2010/love.sln b/platform/msvc2010/love.sln index ef69a54a3..e78aa0104 100644 --- a/platform/msvc2010/love.sln +++ b/platform/msvc2010/love.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 11.00 # Visual C++ Express 2010 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "love", "love.vcxproj", "{B496CCF6-9B6D-0794-8F41-67A6EC86B4AA}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "love", "love.vcxproj", "{0078B97A-F6DB-E014-BED9-BE378D93CEA4}" ProjectSection(ProjectDependencies) = postProject {A3FCC735-3E18-4D6B-9DA9-01D9E910B7F8} = {A3FCC735-3E18-4D6B-9DA9-01D9E910B7F8} EndProjectSection @@ -18,17 +18,17 @@ Global Release Static|x64 = Release Static|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {B496CCF6-9B6D-0794-8F41-67A6EC86B4AA}.Debug Dynamic|Win32.ActiveCfg = Debug Dynamic|Win32 - {B496CCF6-9B6D-0794-8F41-67A6EC86B4AA}.Debug Dynamic|Win32.Build.0 = Debug Dynamic|Win32 - {B496CCF6-9B6D-0794-8F41-67A6EC86B4AA}.Debug Dynamic|x64.ActiveCfg = Debug Dynamic|x64 - {B496CCF6-9B6D-0794-8F41-67A6EC86B4AA}.Release Dynamic|Win32.ActiveCfg = Release Dynamic|Win32 - {B496CCF6-9B6D-0794-8F41-67A6EC86B4AA}.Release Dynamic|Win32.Build.0 = Release Dynamic|Win32 - {B496CCF6-9B6D-0794-8F41-67A6EC86B4AA}.Release Dynamic|x64.ActiveCfg = Release Dynamic|x64 - {B496CCF6-9B6D-0794-8F41-67A6EC86B4AA}.Release Dynamic|x64.Build.0 = Release Dynamic|x64 - {B496CCF6-9B6D-0794-8F41-67A6EC86B4AA}.Release Static|Win32.ActiveCfg = Release Static|Win32 - {B496CCF6-9B6D-0794-8F41-67A6EC86B4AA}.Release Static|Win32.Build.0 = Release Static|Win32 - {B496CCF6-9B6D-0794-8F41-67A6EC86B4AA}.Release Static|x64.ActiveCfg = Release Static|x64 - {B496CCF6-9B6D-0794-8F41-67A6EC86B4AA}.Release Static|x64.Build.0 = Release Static|x64 + {0078B97A-F6DB-E014-BED9-BE378D93CEA4}.Debug Dynamic|Win32.ActiveCfg = Debug Dynamic|Win32 + {0078B97A-F6DB-E014-BED9-BE378D93CEA4}.Debug Dynamic|Win32.Build.0 = Debug Dynamic|Win32 + {0078B97A-F6DB-E014-BED9-BE378D93CEA4}.Debug Dynamic|x64.ActiveCfg = Debug Dynamic|x64 + {0078B97A-F6DB-E014-BED9-BE378D93CEA4}.Release Dynamic|Win32.ActiveCfg = Release Dynamic|Win32 + {0078B97A-F6DB-E014-BED9-BE378D93CEA4}.Release Dynamic|Win32.Build.0 = Release Dynamic|Win32 + {0078B97A-F6DB-E014-BED9-BE378D93CEA4}.Release Dynamic|x64.ActiveCfg = Release Dynamic|x64 + {0078B97A-F6DB-E014-BED9-BE378D93CEA4}.Release Dynamic|x64.Build.0 = Release Dynamic|x64 + {0078B97A-F6DB-E014-BED9-BE378D93CEA4}.Release Static|Win32.ActiveCfg = Release Static|Win32 + {0078B97A-F6DB-E014-BED9-BE378D93CEA4}.Release Static|Win32.Build.0 = Release Static|Win32 + {0078B97A-F6DB-E014-BED9-BE378D93CEA4}.Release Static|x64.ActiveCfg = Release Static|x64 + {0078B97A-F6DB-E014-BED9-BE378D93CEA4}.Release Static|x64.Build.0 = Release Static|x64 {A3FCC735-3E18-4D6B-9DA9-01D9E910B7F8}.Debug Dynamic|Win32.ActiveCfg = Debug Dynamic|Win32 {A3FCC735-3E18-4D6B-9DA9-01D9E910B7F8}.Debug Dynamic|Win32.Build.0 = Debug Dynamic|Win32 {A3FCC735-3E18-4D6B-9DA9-01D9E910B7F8}.Debug Dynamic|x64.ActiveCfg = Debug Dynamic|x64 diff --git a/platform/msvc2010/love.vcxproj b/platform/msvc2010/love.vcxproj index 89db01419..511f92fe1 100644 --- a/platform/msvc2010/love.vcxproj +++ b/platform/msvc2010/love.vcxproj @@ -244,9 +244,6 @@ true - - - @@ -260,6 +257,9 @@ false + + + diff --git a/platform/msvc2010/love.vcxproj.filters b/platform/msvc2010/love.vcxproj.filters index deddec5f8..8c1f9cea4 100644 --- a/platform/msvc2010/love.vcxproj.filters +++ b/platform/msvc2010/love.vcxproj.filters @@ -1,9 +1,9 @@  - - - + + + \ No newline at end of file diff --git a/platform/unix/exclude b/platform/unix/exclude index b0b38ef06..4c61a74c2 100644 --- a/platform/unix/exclude +++ b/platform/unix/exclude @@ -24,4 +24,4 @@ ./modules/thread/sdl/* ./modules/thread/win32/* ./modules/thread/posix/* -./launcher.cpp +./love.cpp diff --git a/platform/unix/gen-makefile b/platform/unix/gen-makefile index 928bfd41d..805686dcb 100644 --- a/platform/unix/gen-makefile +++ b/platform/unix/gen-makefile @@ -12,7 +12,7 @@ SUBDIRS = bin_PROGRAMS = love #love_LDFLAGS = love_LDADD = liblove.la -love_SOURCES = launcher.cpp +love_SOURCES = love.cpp # libLÖVE lib_LTLIBRARIES = liblove.la diff --git a/src/love.cpp b/src/love.cpp index 008a1b652..e7cad5c7a 100644 --- a/src/love.cpp +++ b/src/love.cpp @@ -18,158 +18,39 @@ * 3. This notice may not be removed or altered from any source distribution. **/ -// LOVE -#include "common/config.h" -#include "common/version.h" -#include "common/runtime.h" +#include "modules/love/love.h" +#include + +#ifdef LOVE_BUILD_EXE + +// Lua +extern "C" { + #include + #include + #include +} #ifdef LOVE_WINDOWS #include #endif // LOVE_WINDOWS -#ifdef LOVE_LEGENDARY_CONSOLE_IO_HACK -#include -#include -#include -#include -#endif // LOVE_LEGENDARY_CONSOLE_IO_HACK - -#ifdef LOVE_BUILD_EXE - -// SDL -#include - -// Libraries. -#include "libraries/luasocket/luasocket.h" - -// Scripts -#include "scripts/boot.lua.h" - -#endif // LOVE_BUILD_EXE - -#ifdef LOVE_BUILD_STANDALONE - -// All modules define a c-accessible luaopen -// so let's make use of those, instead -// of addressing implementations directly. -extern "C" -{ - extern int luaopen_love_audio(lua_State*); - extern int luaopen_love_event(lua_State*); - extern int luaopen_love_filesystem(lua_State*); - extern int luaopen_love_font(lua_State*); - extern int luaopen_love_graphics(lua_State*); - extern int luaopen_love_image(lua_State*); - extern int luaopen_love_joystick(lua_State*); - extern int luaopen_love_keyboard(lua_State*); - extern int luaopen_love_mouse(lua_State*); - extern int luaopen_love_physics(lua_State*); - extern int luaopen_love_sound(lua_State*); - extern int luaopen_love_timer(lua_State*); - extern int luaopen_love_thread(lua_State*); - extern int luaopen_love_boot(lua_State*); -} - -static const luaL_Reg modules[] = { - { "love.audio", luaopen_love_audio }, - { "love.event", luaopen_love_event }, - { "love.filesystem", luaopen_love_filesystem }, - { "love.font", luaopen_love_font }, - { "love.graphics", luaopen_love_graphics }, - { "love.image", luaopen_love_image }, - { "love.joystick", luaopen_love_joystick }, - { "love.keyboard", luaopen_love_keyboard }, - { "love.mouse", luaopen_love_mouse }, - { "love.physics", luaopen_love_physics }, - { "love.sound", luaopen_love_sound }, - { "love.timer", luaopen_love_timer }, - { "love.thread", luaopen_love_thread }, - { "love.boot", luaopen_love_boot }, - { 0, 0 } -}; - -#endif // LOVE_BUILD_STANDALONE - -#ifdef LOVE_LEGENDARY_CONSOLE_IO_HACK -int w__openConsole(lua_State * L); -#endif // LOVE_LEGENDARY_CONSOLE_IO_HACK - -extern "C" LOVE_EXPORT int luaopen_love(lua_State * L) -{ - love::luax_insistglobal(L, "love"); - - // Set version information. - lua_pushstring(L, love::VERSION); - lua_setfield(L, -2, "_version"); - - lua_pushnumber(L, love::VERSION_MAJOR); - lua_setfield(L, -2, "_version_major"); - lua_pushnumber(L, love::VERSION_MINOR); - lua_setfield(L, -2, "_version_minor"); - lua_pushnumber(L, love::VERSION_REV); - lua_setfield(L, -2, "_version_revision"); - - lua_pushstring(L, love::VERSION_CODENAME); - lua_setfield(L, -2, "_version_codename"); - -#ifdef LOVE_LEGENDARY_CONSOLE_IO_HACK - lua_pushcfunction(L, w__openConsole); - lua_setfield(L, -2, "_openConsole"); -#endif // LOVE_LEGENDARY_CONSOLE_IO_HACK - - lua_newtable(L); - - for (int i = 0; love::VERSION_COMPATIBILITY[i] != 0; ++i) - { - lua_pushstring(L, love::VERSION_COMPATIBILITY[i]); - lua_rawseti(L, -2, i+1); - } - - lua_setfield(L, -2, "_version_compat"); - -#ifdef LOVE_WINDOWS - lua_pushstring(L, "Windows"); -#elif defined(LOVE_MACOSX) - lua_pushstring(L, "OS X"); -#elif defined(LOVE_LINUX) - lua_pushstring(L, "Linux"); -#else - lua_pushstring(L, "Unknown"); -#endif - lua_setfield(L, -2, "_os"); - -#ifdef LOVE_BUILD_STANDALONE - - // Preload module loaders. - for (int i = 0; modules[i].name != 0; i++) - { - love::luax_preload(L, modules[i].func, modules[i].name); - } - - love::luasocket::__open(L); - -#endif // LOVE_BUILD_STANDALONE - - return 1; -} - #ifdef LOVE_LEGENDARY_UTF8_ARGV_HACK -void get_utf8_arguments(int & argc, char **& argv) +void get_utf8_arguments(int &argc, char **&argv) { LPWSTR cmd = GetCommandLineW(); if (!cmd) return; - LPWSTR * argv_w = CommandLineToArgvW(cmd, &argc); + LPWSTR *argv_w = CommandLineToArgvW(cmd, &argc); - argv = new char*[argc]; + argv = new char *[argc]; - for (int i = 0; i 1 && strcmp(argv[1],"--version") == 0) { - printf("LOVE %s (%s)\n", love::VERSION, love::VERSION_CODENAME); + printf("LOVE %s (%s)\n", love_version(), love_codename()); return 0; } // Create the virtual machine. - lua_State * L = lua_open(); + lua_State *L = lua_open(); luaL_openlibs(L); - love::luax_preload(L, luaopen_love, "love"); + love_preload(L, luaopen_love, "love"); luaopen_love(L); @@ -361,3 +200,4 @@ extern "C" LOVE_EXPORT int lovemain(int argc, char ** argv) return retval; } +#endif // LOVE_BUILD_EXE diff --git a/src/modules/love/love.cpp b/src/modules/love/love.cpp new file mode 100644 index 000000000..94448d448 --- /dev/null +++ b/src/modules/love/love.cpp @@ -0,0 +1,217 @@ +/** + * Copyright (c) 2006-2012 LOVE Development Team + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + **/ + +// LOVE +#include "common/config.h" +#include "common/version.h" +#include "common/runtime.h" + +#include "love.h" + +#ifdef LOVE_WINDOWS +#include +#endif // LOVE_WINDOWS + +#ifdef LOVE_LEGENDARY_CONSOLE_IO_HACK +#include +#include +#include +#include +#endif // LOVE_LEGENDARY_CONSOLE_IO_HACK + +#ifdef LOVE_BUILD_EXE + +// Libraries. +#include "libraries/luasocket/luasocket.h" + +// Scripts +#include "scripts/boot.lua.h" + +#endif // LOVE_BUILD_EXE + +#ifdef LOVE_BUILD_STANDALONE + +// All modules define a c-accessible luaopen +// so let's make use of those, instead +// of addressing implementations directly. +extern "C" +{ + extern int luaopen_love_audio(lua_State*); + extern int luaopen_love_event(lua_State*); + extern int luaopen_love_filesystem(lua_State*); + extern int luaopen_love_font(lua_State*); + extern int luaopen_love_graphics(lua_State*); + extern int luaopen_love_image(lua_State*); + extern int luaopen_love_joystick(lua_State*); + extern int luaopen_love_keyboard(lua_State*); + extern int luaopen_love_mouse(lua_State*); + extern int luaopen_love_physics(lua_State*); + extern int luaopen_love_sound(lua_State*); + extern int luaopen_love_timer(lua_State*); + extern int luaopen_love_thread(lua_State*); + extern int luaopen_love_boot(lua_State*); +} + +static const luaL_Reg modules[] = { + { "love.audio", luaopen_love_audio }, + { "love.event", luaopen_love_event }, + { "love.filesystem", luaopen_love_filesystem }, + { "love.font", luaopen_love_font }, + { "love.graphics", luaopen_love_graphics }, + { "love.image", luaopen_love_image }, + { "love.joystick", luaopen_love_joystick }, + { "love.keyboard", luaopen_love_keyboard }, + { "love.mouse", luaopen_love_mouse }, + { "love.physics", luaopen_love_physics }, + { "love.sound", luaopen_love_sound }, + { "love.timer", luaopen_love_timer }, + { "love.thread", luaopen_love_thread }, + { "love.boot", luaopen_love_boot }, + { 0, 0 } +}; + +#endif // LOVE_BUILD_STANDALONE + +#ifdef LOVE_LEGENDARY_CONSOLE_IO_HACK +int w__openConsole(lua_State * L); +#endif // LOVE_LEGENDARY_CONSOLE_IO_HACK + +extern "C" LOVE_EXPORT const char *love_version() +{ + return love::VERSION; +} + +extern "C" LOVE_EXPORT const char *love_codename() +{ + return love::VERSION_CODENAME; +} + +extern "C" LOVE_EXPORT int luaopen_love(lua_State * L) +{ + love::luax_insistglobal(L, "love"); + + // Set version information. + lua_pushstring(L, love::VERSION); + lua_setfield(L, -2, "_version"); + + lua_pushnumber(L, love::VERSION_MAJOR); + lua_setfield(L, -2, "_version_major"); + lua_pushnumber(L, love::VERSION_MINOR); + lua_setfield(L, -2, "_version_minor"); + lua_pushnumber(L, love::VERSION_REV); + lua_setfield(L, -2, "_version_revision"); + + lua_pushstring(L, love::VERSION_CODENAME); + lua_setfield(L, -2, "_version_codename"); + +#ifdef LOVE_LEGENDARY_CONSOLE_IO_HACK + lua_pushcfunction(L, w__openConsole); + lua_setfield(L, -2, "_openConsole"); +#endif // LOVE_LEGENDARY_CONSOLE_IO_HACK + + lua_newtable(L); + + for (int i = 0; love::VERSION_COMPATIBILITY[i] != 0; ++i) + { + lua_pushstring(L, love::VERSION_COMPATIBILITY[i]); + lua_rawseti(L, -2, i+1); + } + + lua_setfield(L, -2, "_version_compat"); + +#ifdef LOVE_WINDOWS + lua_pushstring(L, "Windows"); +#elif defined(LOVE_MACOSX) + lua_pushstring(L, "OS X"); +#elif defined(LOVE_LINUX) + lua_pushstring(L, "Linux"); +#else + lua_pushstring(L, "Unknown"); +#endif + lua_setfield(L, -2, "_os"); + +#ifdef LOVE_BUILD_STANDALONE + + // Preload module loaders. + for (int i = 0; modules[i].name != 0; i++) + { + love::luax_preload(L, modules[i].func, modules[i].name); + } + + love::luasocket::__open(L); + +#endif // LOVE_BUILD_STANDALONE + + return 1; +} + +#ifdef LOVE_LEGENDARY_CONSOLE_IO_HACK + +int w__openConsole(lua_State * L) +{ + static bool is_open = false; + if (is_open) + return 0; + is_open = true; + + if (GetConsoleWindow() != NULL || AllocConsole() == 0) + return 0; + + const int MAX_CONSOLE_LINES = 5000; + CONSOLE_SCREEN_BUFFER_INFO console_info; + + // Set size. + GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &console_info); + console_info.dwSize.Y = MAX_CONSOLE_LINES; + SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), console_info.dwSize); + + SetConsoleTitle(TEXT("LOVE Console")); + + FILE * fp; + + // Redirect stdout. + fp = freopen("CONOUT$", "w", stdout); + if (L && fp == NULL) + luaL_error(L, "Console redirection of stdout failed."); + + // Redirect stdin. + fp = freopen("CONIN$", "r", stdin); + if (L && fp == NULL) + luaL_error(L, "Console redirection of stdin failed."); + + // Redirect stderr. + fp = freopen("CONOUT$", "w", stderr); + if (L && fp == NULL) + luaL_error(L, "Console redirection of stderr failed."); + + return 0; +} + +#endif // LOVE_LEGENDARY_CONSOLE_IO_HACK + +extern "C" LOVE_EXPORT int luaopen_love_boot(lua_State *L) +{ + if (luaL_loadbuffer(L, (const char *)love::boot_lua, sizeof(love::boot_lua), "boot.lua") == 0) + lua_call(L, 0, 1); + return 1; +} + + + diff --git a/src/launcher.cpp b/src/modules/love/love.h similarity index 75% rename from src/launcher.cpp rename to src/modules/love/love.h index ab46367b7..106d4f497 100644 --- a/src/launcher.cpp +++ b/src/modules/love/love.h @@ -18,17 +18,13 @@ * 3. This notice may not be removed or altered from any source distribution. **/ +// LOVE #include "common/config.h" -#include -extern "C" -{ - extern int lovemain(int argc, char **argv); -} +// Forward declare lua_State. +struct lua_State; -#ifdef LOVE_BUILD_EXE -int main(int argc, char **argv) -{ - return lovemain(argc, argv); -} -#endif // LOVE_BUILD_EXE +extern "C" LOVE_EXPORT const char *love_version(); +extern "C" LOVE_EXPORT const char *love_codename(); +extern "C" LOVE_EXPORT int luaopen_love(lua_State *L); +extern "C" LOVE_EXPORT int luaopen_love_boot(lua_State *L); \ No newline at end of file