Mercurial > love-experiments
annotate src/love.cpp @ 1448:108ee2e81f65 default tip
Fix a case typo, imageData.h -> ImageData.h
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Sat, 18 Jan 2014 13:57:44 +0100 |
| parents | 3f4ed5e896df |
| children |
| rev | line source |
|---|---|
| 1096 | 1 /** |
|
1282
b7f097053d74
Updated copyright text for the new year
Alex Szpakowski <slime73@gmail.com>
parents:
1096
diff
changeset
|
2 * Copyright (c) 2006-2013 LOVE Development Team |
| 1096 | 3 * |
| 4 * This software is provided 'as-is', without any express or implied | |
| 5 * warranty. In no event will the authors be held liable for any damages | |
| 6 * arising from the use of this software. | |
| 7 * | |
| 8 * Permission is granted to anyone to use this software for any purpose, | |
| 9 * including commercial applications, and to alter it and redistribute it | |
| 10 * freely, subject to the following restrictions: | |
| 11 * | |
| 12 * 1. The origin of this software must not be misrepresented; you must not | |
| 13 * claim that you wrote the original software. If you use this software | |
| 14 * in a product, an acknowledgment in the product documentation would be | |
| 15 * appreciated but is not required. | |
| 16 * 2. Altered source versions must be plainly marked as such, and must not be | |
| 17 * misrepresented as being the original software. | |
| 18 * 3. This notice may not be removed or altered from any source distribution. | |
| 19 **/ | |
| 20 | |
| 21 #include "modules/love/love.h" | |
| 22 #include <SDL.h> | |
| 23 | |
| 24 #ifdef LOVE_BUILD_EXE | |
| 25 | |
| 26 // Lua | |
| 27 extern "C" { | |
| 28 #include <lua.h> | |
| 29 #include <lualib.h> | |
| 30 #include <lauxlib.h> | |
| 31 } | |
| 32 | |
| 33 #ifdef LOVE_WINDOWS | |
| 34 #include <windows.h> | |
| 35 #endif // LOVE_WINDOWS | |
| 36 | |
| 37 #ifdef LOVE_LEGENDARY_UTF8_ARGV_HACK | |
| 38 | |
| 39 void get_utf8_arguments(int &argc, char **&argv) | |
| 40 { | |
| 41 LPWSTR cmd = GetCommandLineW(); | |
| 42 | |
| 43 if (!cmd) | |
| 44 return; | |
| 45 | |
| 46 LPWSTR *argv_w = CommandLineToArgvW(cmd, &argc); | |
| 47 | |
| 48 argv = new char *[argc]; | |
| 49 | |
| 50 for (int i = 0; i < argc; ++i) | |
| 51 { | |
| 52 // Size of wide char buffer (plus one for trailing '\0'). | |
| 53 size_t wide_len = wcslen(argv_w[i]) + 1; | |
| 54 | |
| 55 // Get size in UTF-8. | |
| 56 int utf8_size = WideCharToMultiByte(CP_UTF8, 0, argv_w[i], wide_len, argv[i], 0, 0, 0); | |
| 57 | |
| 58 argv[i] = new char[utf8_size]; | |
| 59 | |
| 60 // Convert to UTF-8. | |
| 61 int ok = WideCharToMultiByte(CP_UTF8, 0, argv_w[i], wide_len, argv[i], utf8_size, 0, 0); | |
| 62 | |
| 63 int len = strlen(argv[i]); | |
| 64 | |
| 65 if (!ok) | |
| 66 printf("Warning: could not convert to UTF8.\n"); | |
| 67 } | |
| 68 | |
| 69 LocalFree(argv_w); | |
| 70 } | |
| 71 | |
| 72 #endif // LOVE_LEGENDARY_UTF8_ARGV_HACK | |
| 73 | |
| 74 #ifdef LOVE_LEGENDARY_LIBSTDCXX_HACK | |
| 75 | |
| 76 #include <iostream> | |
| 77 | |
| 78 // Workarounds for symbols that are missing from Leopard stdlibc++.dylib. | |
| 79 // http://stackoverflow.com/questions/3484043/os-x-program-runs-on-dev-machine-crashing-horribly-on-others | |
| 80 _GLIBCXX_BEGIN_NAMESPACE(std) | |
| 81 // From ostream_insert.h | |
| 82 template ostream& __ostream_insert(ostream&, const char*, streamsize); | |
| 83 | |
| 84 #ifdef _GLIBCXX_USE_WCHAR_T | |
| 85 template wostream& __ostream_insert(wostream&, const wchar_t*, streamsize); | |
| 86 #endif | |
| 87 | |
| 88 // From ostream.tcc | |
| 89 template ostream& ostream::_M_insert(long); | |
| 90 template ostream& ostream::_M_insert(unsigned long); | |
| 91 template ostream& ostream::_M_insert(bool); | |
| 92 #ifdef _GLIBCXX_USE_LONG_LONG | |
| 93 template ostream& ostream::_M_insert(long long); | |
| 94 template ostream& ostream::_M_insert(unsigned long long); | |
| 95 #endif | |
| 96 template ostream& ostream::_M_insert(double); | |
| 97 template ostream& ostream::_M_insert(long double); | |
| 98 template ostream& ostream::_M_insert(const void*); | |
| 99 | |
| 100 #ifdef _GLIBCXX_USE_WCHAR_T | |
| 101 template wostream& wostream::_M_insert(long); | |
| 102 template wostream& wostream::_M_insert(unsigned long); | |
| 103 template wostream& wostream::_M_insert(bool); | |
| 104 #ifdef _GLIBCXX_USE_LONG_LONG | |
| 105 template wostream& wostream::_M_insert(long long); | |
| 106 template wostream& wostream::_M_insert(unsigned long long); | |
| 107 #endif | |
| 108 template wostream& wostream::_M_insert(double); | |
| 109 template wostream& wostream::_M_insert(long double); | |
| 110 template wostream& wostream::_M_insert(const void*); | |
| 111 #endif | |
| 112 | |
| 113 _GLIBCXX_END_NAMESPACE | |
| 114 | |
| 115 #endif // LOVE_LEGENDARY_LIBSTDCXX_HACK | |
| 116 | |
| 117 static int love_preload(lua_State *L, lua_CFunction f, const char *name) | |
| 118 { | |
| 119 lua_getglobal(L, "package"); | |
| 120 lua_getfield(L, -1, "preload"); | |
| 121 lua_pushcfunction(L, f); | |
| 122 lua_setfield(L, -2, name); | |
| 123 lua_pop(L, 2); | |
| 124 return 0; | |
| 125 } | |
| 126 | |
| 127 int main(int argc, char **argv) | |
| 128 { | |
| 129 #ifdef LOVE_LEGENDARY_UTF8_ARGV_HACK | |
| 130 int hack_argc = 0; char **hack_argv = 0; | |
| 131 get_utf8_arguments(hack_argc, hack_argv); | |
| 132 argc = hack_argc; | |
| 133 argv = hack_argv; | |
| 134 #endif // LOVE_LEGENDARY_UTF8_ARGV_HACK | |
| 135 | |
| 136 // Oh, you just want the version? Okay! | |
| 137 if (argc > 1 && strcmp(argv[1],"--version") == 0) | |
| 138 { | |
| 139 printf("LOVE %s (%s)\n", love_version(), love_codename()); | |
| 140 return 0; | |
| 141 } | |
| 142 | |
| 143 // Create the virtual machine. | |
|
1308
3f4ed5e896df
Replaced deprecated lua_open calls with luaL_newstate
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
144 lua_State *L = luaL_newstate(); |
| 1096 | 145 luaL_openlibs(L); |
| 146 | |
| 147 love_preload(L, luaopen_love, "love"); | |
| 148 | |
| 149 luaopen_love(L); | |
| 150 | |
| 151 // Add command line arguments to global arg (like stand-alone Lua). | |
| 152 { | |
| 153 lua_newtable(L); | |
| 154 | |
| 155 if (argc > 0) | |
| 156 { | |
| 157 lua_pushstring(L, argv[0]); | |
| 158 lua_rawseti(L, -2, -2); | |
| 159 } | |
| 160 | |
| 161 lua_pushstring(L, "embedded boot.lua"); | |
| 162 lua_rawseti(L, -2, -1); | |
| 163 | |
| 164 for (int i = 1; i<argc; i++) | |
| 165 { | |
| 166 lua_pushstring(L, argv[i]); | |
| 167 lua_rawseti(L, -2, i); | |
| 168 } | |
| 169 | |
| 170 lua_setglobal(L, "arg"); | |
| 171 } | |
| 172 | |
| 173 // Add love.__exe = true. | |
| 174 // This indicates that we're running the | |
| 175 // standalone version of love, and not the | |
| 176 // DLL version. | |
| 177 { | |
| 178 lua_getglobal(L, "love"); | |
| 179 lua_pushboolean(L, 1); | |
| 180 lua_setfield(L, -2, "_exe"); | |
| 181 lua_pop(L, 1); | |
| 182 } | |
| 183 | |
| 184 // Boot | |
| 185 luaopen_love_boot(L); | |
| 186 lua_call(L, 0, 1); | |
| 187 | |
| 188 int retval = 0; | |
| 189 if (lua_isnumber(L, 1)) | |
| 190 retval = (int) lua_tonumber(L, 1); | |
| 191 | |
| 192 lua_close(L); | |
| 193 | |
| 194 #ifdef LOVE_LEGENDARY_UTF8_ARGV_HACK | |
| 195 if (hack_argv) | |
| 196 { | |
| 197 for (int i = 0; i<hack_argc; ++i) | |
| 198 delete [] hack_argv[i]; | |
| 199 delete [] hack_argv; | |
| 200 } | |
| 201 #endif // LOVE_LEGENDARY_UTF8_ARGV_HACK | |
| 202 return retval; | |
| 203 } | |
| 204 | |
| 205 #endif // LOVE_BUILD_EXE |
