summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2022-11-07 17:16:26 +1100
committerDamien George <damien@micropython.org>2022-11-07 17:18:31 +1100
commit1ed740b152b4acd47aeb02da114cdb3150009a13 (patch)
tree89862315e9a5f848618e2f783a43195d83d9493e
parentdb978d715510a1fa01e4c13d209d0fc0df0b23d1 (diff)
webassembly/README: Update README to describe new stdout behaviour.
Signed-off-by: Damien George <damien@micropython.org>
-rw-r--r--ports/webassembly/README.md21
1 files changed, 13 insertions, 8 deletions
diff --git a/ports/webassembly/README.md b/ports/webassembly/README.md
index 3b577233f..9ad04ccb9 100644
--- a/ports/webassembly/README.md
+++ b/ports/webassembly/README.md
@@ -55,9 +55,9 @@ mp_js_do_str("print('hello world')\n");
Running with HTML
-----------------
-The prerequisite for browser operation of micropython.js is an element with
-the id `mp_js_stdout` which receives `print` events. The following code
-demonstrates basic functionality:
+The prerequisite for browser operation of micropython.js is to listen to the
+`micropython-print` event, which is passed data when MicroPython code prints
+something to stdout. The following code demonstrates basic functionality:
```html
<!doctype html>
@@ -66,14 +66,19 @@ demonstrates basic functionality:
<script src="build/micropython.js"></script>
</head>
<body>
- <div id='mp_js_stdout'></div>
+ <pre id="micropython-stdout"></pre>
<script>
- mp_js_stdout.addEventListener('print', function(e) {
- document.write(e.data);
+ document.addEventListener("micropython-print", function(e) {
+ let output = document.getElementById("micropython-stdout");
+ output.innerText += e.data;
}, false);
- mp_js_init(64 * 1024);
- mp_js_do_str('print(\'hello world\')');
+ var mp_js_startup = Module["onRuntimeInitialized"];
+ Module["onRuntimeInitialized"] = async function() {
+ mp_js_startup();
+ mp_js_init(64 * 1024);
+ mp_js_do_str("print('hello world')");
+ };
</script>
</body>
</html>