Atlas - SDL_sysmain_runapp.c

Home / ext / SDL / src / main / emscripten Lines: 1 | Size: 2584 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 Sam Lantinga <[email protected]> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21#include "SDL_internal.h" 22 23#ifdef SDL_PLATFORM_EMSCRIPTEN 24 25#include "../SDL_main_callbacks.h" 26 27#include <emscripten/emscripten.h> 28 29EM_JS_DEPS(sdlrunapp, "$dynCall,$stringToNewUTF8"); 30 31// even though we reference the C runtime's free() in other places, it appears 32// to be inlined more aggressively in Emscripten 4, so we need a reference to 33// it here, too, so the inlined Javascript doesn't fail to find it. 34EMSCRIPTEN_KEEPALIVE void force_free(void *ptr) { free(ptr); } // This should NOT be SDL_free() 35 36int SDL_RunApp(int argc, char *argv[], SDL_main_func mainFunction, void * reserved) 37{ 38 (void)reserved; 39 40 // Move any URL params that start with "SDL_" over to environment 41 // variables, so the hint system can pick them up, etc, much like a user 42 // can set them from a shell prompt on a desktop machine. Ignore all 43 // other params, in case the app wants to use them for something. 44 MAIN_THREAD_EM_ASM({ 45 var parms = new URLSearchParams(window.location.search); 46 for (const [key, value] of parms) { 47 if (key.startsWith("SDL_")) { 48 var ckey = stringToNewUTF8(key); 49 var cvalue = stringToNewUTF8(value); 50 if ((ckey != 0) && (cvalue != 0)) { 51 //console.log("Setting SDL env var '" + key + "' to '" + value + "' ..."); 52 dynCall('iiii', $0, [ckey, cvalue, 1]); 53 } 54 _force_free(ckey); // these must use free(), not SDL_free()! 55 _force_free(cvalue); 56 } 57 } 58 }, SDL_setenv_unsafe); 59 60 return SDL_CallMainFunction(argc, argv, mainFunction); 61} 62 63#endif 64
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.