diff options
-rw-r--r-- | src/library_browser.js | 10 | ||||
-rw-r--r-- | system/include/emscripten.h | 1 | ||||
-rw-r--r-- | tests/emscripten_api_browser.cpp | 4 |
3 files changed, 13 insertions, 2 deletions
diff --git a/src/library_browser.js b/src/library_browser.js index 66aeeaf8..a37ef612 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -3,6 +3,16 @@ // Utilities for browser environments mergeInto(LibraryManager.library, { + emscripten_async_run_script__deps: ['emscripten_run_script'], + emscripten_async_run_script: function(script, millis) { + Module['noExitRuntime'] = true; + + // TODO: cache these to avoid generating garbage + setTimeout(function() { + _emscripten_run_script(script); + }, millis); + }, + emscripten_set_main_loop: function(func, fps) { Module['noExitRuntime'] = true; diff --git a/system/include/emscripten.h b/system/include/emscripten.h index 7bb2ae8e..fa95645a 100644 --- a/system/include/emscripten.h +++ b/system/include/emscripten.h @@ -17,6 +17,7 @@ extern "C" { */ extern void emscripten_run_script(const char *script); extern int emscripten_run_script_int(const char *script); +extern void emscripten_async_run_script(const char *script, int millis); /* * Set a C function as the main event loop. The JS environment diff --git a/tests/emscripten_api_browser.cpp b/tests/emscripten_api_browser.cpp index 4d425120..0226eae5 100644 --- a/tests/emscripten_api_browser.cpp +++ b/tests/emscripten_api_browser.cpp @@ -9,7 +9,7 @@ int last = 0; extern "C" { -void third() { +void __attribute__((used)) third() { int now = SDL_GetTicks(); printf("thard! %d\n", now); assert(fabs(now - last - 1000) < 500); @@ -22,7 +22,7 @@ void second() { printf("sacond! %d\n", now); assert(fabs(now - last - 500) < 250); last = now; - emscripten_async_call(third, 1000); + emscripten_async_run_script("_third()", 1000); } } |