diff options
| author | Ben Harris <bjh21@bjh21.me.uk> | 2022-12-09 13:56:12 +0000 |
|---|---|---|
| committer | Ben Harris <bjh21@bjh21.me.uk> | 2023-01-19 20:34:48 +0000 |
| commit | 9d7b044c01680e408094d3bae82f622ae8a5b48b (patch) | |
| tree | 60ff57c078be6ac247fe1e18d007ed955ad9fb1e /emcc.c | |
| parent | 420663d47790a7e34a1662d679a0c00efdb5b7e5 (diff) | |
| download | puzzles-9d7b044c01680e408094d3bae82f622ae8a5b48b.zip puzzles-9d7b044c01680e408094d3bae82f622ae8a5b48b.tar.gz puzzles-9d7b044c01680e408094d3bae82f622ae8a5b48b.tar.bz2 puzzles-9d7b044c01680e408094d3bae82f622ae8a5b48b.tar.xz | |
js: Simpler and more robust startup procedure
Previously, we initialised all of the JavaScript event handlers as soon
at the DOM was loaded, and then called main() ourselves once the
Emscripten runtime was ready. This was slightly dangerous since it
depended on none of those event handlers' being called before main().
In practice this was difficult because most of the elements the event
handlers were attached to were invisible, but it did limit what event
handlers could safely be used.
Now, the event handlers are initialised from main(). This makes things
work in a sufficiently conventional way that we can just let the
Emscripten run-time call main() in its usual way, rather than involving
ourselves in the minutiae of Emscripten's startup.
Diffstat (limited to 'emcc.c')
| -rw-r--r-- | emcc.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -43,6 +43,8 @@ /* * Extern references to Javascript functions provided in emcclib.js. */ +extern void js_init_puzzle(void); +extern void js_post_init(void); extern void js_debug(const char *); extern void js_error_box(const char *message); extern void js_remove_type_dropdown(void); @@ -937,6 +939,11 @@ int main(int argc, char **argv) int i; /* + * Initialise JavaScript event handlers. + */ + js_init_puzzle(); + + /* * Instantiate a midend. */ me = midend_new(NULL, &thegame, &js_drawing, NULL); @@ -1041,6 +1048,11 @@ int main(int argc, char **argv) js_error_box(param_err); /* + * Reveal the puzzle! + */ + js_post_init(); + + /* * Done. Return to JS, and await callbacks! */ return 0; |