Skip to content

Instantly share code, notes, and snippets.

@rhysd rhysd/cmd

Created Aug 11, 2018
Embed
What would you like to do?
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
You can’t perform that action at this time.