-
-
Save rhysd/ef043af4c34f62c4fde9c426ec43c1ae to your computer and use it in GitHub Desktop.
setjmp/longjmp test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
emcc main.c --js-library main.js -o hello.html -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <setjmp.h> | |
void js_timer_start(void); | |
static jmp_buf mark; | |
void on_timer_finish() { | |
longjmp(mark, -1); | |
} | |
int main() | |
{ | |
if (setjmp(mark) != 0) { | |
printf("hello!\n"); | |
return 0; | |
} | |
js_timer_start(); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mergeInto(LibraryManager.library, { | |
js_timer_start: function() { | |
setTimeout(() => { | |
Module.ccall('on_timer_finish', 'void', [], []); | |
}, 5000); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment