webassembly/README: Update README to describe new stdout behaviour.

Signed-off-by: Damien George <damien@micropython.org>
pull/9710/head
Damien George 2022-11-07 17:16:26 +11:00
rodzic db978d7155
commit 1ed740b152
1 zmienionych plików z 13 dodań i 8 usunięć

Wyświetl plik

@ -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>