aboutsummaryrefslogtreecommitdiff
path: root/emcclib.js
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2022-12-09 13:56:12 +0000
committerBen Harris <bjh21@bjh21.me.uk>2023-01-19 20:34:48 +0000
commit9d7b044c01680e408094d3bae82f622ae8a5b48b (patch)
tree60ff57c078be6ac247fe1e18d007ed955ad9fb1e /emcclib.js
parent420663d47790a7e34a1662d679a0c00efdb5b7e5 (diff)
downloadpuzzles-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 'emcclib.js')
-rw-r--r--emcclib.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/emcclib.js b/emcclib.js
index 98c20f6..676c429 100644
--- a/emcclib.js
+++ b/emcclib.js
@@ -17,6 +17,23 @@
mergeInto(LibraryManager.library, {
/*
+ * void js_init_puzzle(void);
+ *
+ * Called at the start of main() to set up event handlers.
+ */
+ js_init_puzzle: function() {
+ initPuzzle();
+ },
+ /*
+ * void js_post_init(void);
+ *
+ * Called at the end of main() once the initial puzzle has been
+ * started.
+ */
+ js_post_init: function() {
+ post_init();
+ },
+ /*
* void js_debug(const char *message);
*
* A function to write a diagnostic to the Javascript console.