diff options
| -rw-r--r-- | ports/webassembly/README.md | 21 |
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> |
