int main(int argc, char **argv) { #ifdef LOVE_LEGENDARY_UTF8_ARGV_HACK int hack_argc = 0; char **hack_argv = 0; get_utf8_arguments(hack_argc, hack_argv); argc = hack_argc; argv = hack_argv; #endif // LOVE_LEGENDARY_UTF8_ARGV_HACK #ifdef LOVE_LEGENDARY_APP_ARGV_HACK int hack_argc = 0; char **hack_argv = 0; get_app_arguments(argc, argv, hack_argc, hack_argv); argc = hack_argc; argv = hack_argv; #endif // LOVE_LEGENDARY_APP_ARGV_HACK if (strcmp(LOVE_VERSION_STRING, love_version()) != 0) { printf("Version mismatch detected!\nLOVE binary is version %s\n" "LOVE library is version %s\n", LOVE_VERSION_STRING, love_version()); return 1; } // Oh, you just want the version? Okay! if (argc > 1 && strcmp(argv[1], "--version") == 0) { printf("LOVE %s (%s)\n", love_version(), love_codename()); return 0; } // Create the virtual machine. lua_State *L = luaL_newstate(); luaL_openlibs(L); // Add love to package.preload for easy requiring. love_preload(L, luaopen_love, "love"); // 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 < argc; i++) { lua_pushstring(L, argv[i]); lua_rawseti(L, -2, i); } lua_setglobal(L, "arg"); } // require "love" lua_getglobal(L, "require"); lua_pushstring(L, "love"); lua_call(L, 1, 1); // leave the returned table on the stack. // Add love._exe = true. // This indicates that we're running the standalone version of love, and not // the library version. { lua_pushboolean(L, 1); lua_setfield(L, -2, "_exe"); } // Pop the love table returned by require "love". lua_pop(L, 1); // require "love.boot" (preloaded when love was required.) lua_getglobal(L, "require"); lua_pushstring(L, "love.boot"); lua_call(L, 1, 1); // Call the returned boot function. lua_call(L, 0, 1); int retval = 0; if (lua_isnumber(L, -1)) retval = (int) lua_tonumber(L, -1); lua_close(L); #if defined(LOVE_LEGENDARY_UTF8_ARGV_HACK) || defined(LOVE_LEGENDARY_APP_ARGV_HACK) if (hack_argv) { for (int i = 0; i<hack_argc; ++i) delete [] hack_argv[i]; delete [] hack_argv; } #endif // LOVE_LEGENDARY_UTF8_ARGV_HACK || LOVE_LEGENDARY_APP_ARGV_HACK return retval; }
int main(int argc, char **argv) { int retval = 0; #ifdef LOVE_IOS int orig_argc = argc; char **orig_argv = argv; // on iOS we should never programmatically exit the app, so we'll just // "restart" when that is attempted. Games which use threads might cause // some issues if the threads aren't cleaned up properly... while (true) { argc = orig_argc; argv = orig_argv; #endif #ifdef LOVE_LEGENDARY_APP_ARGV_HACK int hack_argc = 0; char **hack_argv = 0; get_app_arguments(argc, argv, hack_argc, hack_argv); argc = hack_argc; argv = hack_argv; #endif // LOVE_LEGENDARY_APP_ARGV_HACK if (strcmp(LOVE_VERSION_STRING, love_version()) != 0) { printf("Version mismatch detected!\nLOVE binary is version %s\n" "LOVE library is version %s\n", LOVE_VERSION_STRING, love_version()); return 1; } // Oh, you just want the version? Okay! if (argc > 1 && strcmp(argv[1], "--version") == 0) { printf("LOVE %s (%s)\n", love_version(), love_codename()); return 0; } // Create the virtual machine. lua_State *L = luaL_newstate(); luaL_openlibs(L); #ifdef LOVE_ANDROID luaJIT_setmode(L, 0, LUAJIT_MODE_ENGINE| LUAJIT_MODE_OFF); lua_register(L, "print", l_print_sdl_log); #endif // Add love to package.preload for easy requiring. love_preload(L, luaopen_love, "love"); // 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 < argc; i++) { lua_pushstring(L, argv[i]); lua_rawseti(L, -2, i); } lua_setglobal(L, "arg"); } // require "love" lua_getglobal(L, "require"); lua_pushstring(L, "love"); lua_call(L, 1, 1); // leave the returned table on the stack. // Add love._exe = true. // This indicates that we're running the standalone version of love, and not // the library version. { lua_pushboolean(L, 1); lua_setfield(L, -2, "_exe"); } // Pop the love table returned by require "love". lua_pop(L, 1); // require "love.boot" (preloaded when love was required.) lua_getglobal(L, "require"); lua_pushstring(L, "love.boot"); lua_call(L, 1, 1); // Call the returned boot function. lua_call(L, 0, 1); if (lua_isnumber(L, -1)) retval = (int) lua_tonumber(L, -1); lua_close(L); #if defined(LOVE_LEGENDARY_APP_ARGV_HACK) if (hack_argv) { for (int i = 0; i<hack_argc; ++i) delete [] hack_argv[i]; delete [] hack_argv; } #endif // LOVE_LEGENDARY_APP_ARGV_HACK #ifdef LOVE_IOS } // while (true) #endif #ifdef LOVE_ANDROID SDL_Quit(); #endif return retval; }