/** * 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 #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*); } 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 }, { 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) { LPWSTR cmd = GetCommandLineW(); if (!cmd) return; LPWSTR * argv_w = CommandLineToArgvW(cmd, &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); return 0; } // Create the virtual machine. lua_State * L = lua_open(); luaL_openlibs(L); love::luax_preload(L, luaopen_love, "love"); luaopen_love(L); // Add command line arguments to global arg (like stand-alone Lua). { lua_newtable(L); if (argc > 0) { lua_pushstring(L, argv[0]); lua_rawseti(L, -2, -2); } lua_pushstring(L, "embedded boot.lua"); lua_rawseti(L, -2, -1); for (int i = 1; i