webassembly/README: Update README to describe new stdout behaviour.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
db978d7155
commit
1ed740b152
|
@ -55,9 +55,9 @@ mp_js_do_str("print('hello world')\n");
|
||||||
Running with HTML
|
Running with HTML
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
The prerequisite for browser operation of micropython.js is an element with
|
The prerequisite for browser operation of micropython.js is to listen to the
|
||||||
the id `mp_js_stdout` which receives `print` events. The following code
|
`micropython-print` event, which is passed data when MicroPython code prints
|
||||||
demonstrates basic functionality:
|
something to stdout. The following code demonstrates basic functionality:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
|
@ -66,14 +66,19 @@ demonstrates basic functionality:
|
||||||
<script src="build/micropython.js"></script>
|
<script src="build/micropython.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id='mp_js_stdout'></div>
|
<pre id="micropython-stdout"></pre>
|
||||||
<script>
|
<script>
|
||||||
mp_js_stdout.addEventListener('print', function(e) {
|
document.addEventListener("micropython-print", function(e) {
|
||||||
document.write(e.data);
|
let output = document.getElementById("micropython-stdout");
|
||||||
|
output.innerText += e.data;
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
mp_js_init(64 * 1024);
|
var mp_js_startup = Module["onRuntimeInitialized"];
|
||||||
mp_js_do_str('print(\'hello world\')');
|
Module["onRuntimeInitialized"] = async function() {
|
||||||
|
mp_js_startup();
|
||||||
|
mp_js_init(64 * 1024);
|
||||||
|
mp_js_do_str("print('hello world')");
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue