mirror of
https://github.com/micropython/micropython.git
synced 2026-01-06 20:20:14 +01:00
webassembly/library: Extract and send data to print as UInt8Array.
This allows utf-8 data to work. It's the receiving layer's responsibility to deal with decoding the data.
This commit is contained in:
committed by
Damien George
parent
f3d9fe7b2c
commit
db19ee7e15
@@ -26,16 +26,12 @@
|
||||
|
||||
mergeInto(LibraryManager.library, {
|
||||
mp_js_write: function(ptr, len) {
|
||||
for (var i = 0; i < len; ++i) {
|
||||
if (typeof window === 'undefined') {
|
||||
var b = Buffer.alloc(1);
|
||||
b.writeInt8(getValue(ptr + i, 'i8'));
|
||||
process.stdout.write(b);
|
||||
} else {
|
||||
var c = String.fromCharCode(getValue(ptr + i, 'i8'));
|
||||
var printEvent = new CustomEvent('micropython-print', { detail: c });
|
||||
document.dispatchEvent(printEvent);
|
||||
}
|
||||
const buffer = HEAPU8.subarray(ptr, ptr + len)
|
||||
if (typeof window === 'undefined') {
|
||||
process.stdout.write(buffer);
|
||||
} else {
|
||||
const printEvent = new CustomEvent('micropython-print', { detail: buffer });
|
||||
document.dispatchEvent(printEvent);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user