Skip to content

Instantly share code, notes, and snippets.

@rhysd
Created August 11, 2018 02:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhysd/ef043af4c34f62c4fde9c426ec43c1ae to your computer and use it in GitHub Desktop.
Save rhysd/ef043af4c34f62c4fde9c426ec43c1ae to your computer and use it in GitHub Desktop.
setjmp/longjmp test
emcc main.c --js-library main.js -o hello.html -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall']"
#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;
}
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