Skip to content

Commit

Permalink
add emscripten_async_run_script
Browse files Browse the repository at this point in the history
  • Loading branch information
kripken committed Apr 19, 2012
1 parent 7fe2743 commit 3b725e2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/library_browser.js
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions system/include/emscripten.h
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/emscripten_api_browser.cpp
Expand Up @@ -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);
Expand All @@ -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);
}

}
Expand Down

0 comments on commit 3b725e2

Please sign in to comment.