File tree Expand file tree Collapse file tree 2 files changed +7
-11
lines changed
Expand file tree Collapse file tree 2 files changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ something to stdout. The following code demonstrates basic functionality:
7070 <script >
7171 document .addEventListener (" micropython-print" , function (e ) {
7272 let output = document .getElementById (" micropython-stdout" );
73- output .innerText += e .detail ;
73+ output .innerText += new TextDecoder (). decode ( e .detail ) ;
7474 }, false );
7575
7676 var mp_js_startup = Module[" onRuntimeInitialized" ];
Original file line number Diff line number Diff line change 2626
2727mergeInto ( LibraryManager . library , {
2828 mp_js_write : function ( ptr , len ) {
29- for ( var i = 0 ; i < len ; ++ i ) {
30- if ( typeof window === 'undefined' ) {
31- var b = Buffer . alloc ( 1 ) ;
32- b . writeInt8 ( getValue ( ptr + i , 'i8' ) ) ;
33- process . stdout . write ( b ) ;
34- } else {
35- var c = String . fromCharCode ( getValue ( ptr + i , 'i8' ) ) ;
36- var printEvent = new CustomEvent ( 'micropython-print' , { detail : c } ) ;
37- document . dispatchEvent ( printEvent ) ;
38- }
29+ const buffer = HEAPU8 . subarray ( ptr , ptr + len )
30+ if ( typeof window === 'undefined' ) {
31+ process . stdout . write ( buffer ) ;
32+ } else {
33+ const printEvent = new CustomEvent ( 'micropython-print' , { detail : buffer } ) ;
34+ document . dispatchEvent ( printEvent ) ;
3935 }
4036 } ,
4137
You can’t perform that action at this time.
0 commit comments