summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/webassembly/library.js10
-rw-r--r--ports/webassembly/mpconfigport.h4
-rw-r--r--ports/webassembly/mphalport.c11
3 files changed, 12 insertions, 13 deletions
diff --git a/ports/webassembly/library.js b/ports/webassembly/library.js
index d1266598d..db5bac269 100644
--- a/ports/webassembly/library.js
+++ b/ports/webassembly/library.js
@@ -25,16 +25,6 @@
*/
mergeInto(LibraryManager.library, {
- mp_js_write: function(ptr, len) {
- const buffer = HEAPU8.subarray(ptr, ptr + len)
- if (ENVIRONMENT_IS_NODE) {
- process.stdout.write(buffer);
- } else {
- const printEvent = new CustomEvent('micropython-print', { detail: buffer });
- document.dispatchEvent(printEvent);
- }
- },
-
// This string will be emitted directly into the output file by Emscripten.
mp_js_ticks_ms__postset: "var MP_JS_EPOCH = Date.now()",
diff --git a/ports/webassembly/mpconfigport.h b/ports/webassembly/mpconfigport.h
index 79537dd72..6b0f2753a 100644
--- a/ports/webassembly/mpconfigport.h
+++ b/ports/webassembly/mpconfigport.h
@@ -46,6 +46,7 @@
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
#define MICROPY_ENABLE_DOC_STRING (1)
#define MICROPY_WARNINGS (1)
+#define MICROPY_ERROR_PRINTER (&mp_stderr_print)
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
#define MICROPY_USE_INTERNAL_ERRNO (1)
#define MICROPY_USE_INTERNAL_PRINTF (0)
@@ -60,7 +61,6 @@
#endif
#define MICROPY_VFS_POSIX (MICROPY_VFS)
#define MICROPY_PY_SYS_PLATFORM "webassembly"
-#define MICROPY_PY_SYS_STDFILES (0)
#define MICROPY_EVENT_POLL_HOOK \
do { \
@@ -102,4 +102,6 @@ typedef long mp_off_t;
#define _GNU_SOURCE
#endif
+extern const struct _mp_print_t mp_stderr_print;
+
uint32_t mp_js_random_u32(void);
diff --git a/ports/webassembly/mphalport.c b/ports/webassembly/mphalport.c
index 72a326e30..9ab47762e 100644
--- a/ports/webassembly/mphalport.c
+++ b/ports/webassembly/mphalport.c
@@ -24,12 +24,19 @@
* THE SOFTWARE.
*/
+#include <unistd.h>
#include "library.h"
#include "mphalport.h"
+static void stderr_print_strn(void *env, const char *str, size_t len) {
+ (void)env;
+ write(2, str, len);
+}
+
+const mp_print_t mp_stderr_print = {NULL, stderr_print_strn};
+
mp_uint_t mp_hal_stdout_tx_strn(const char *str, size_t len) {
- mp_js_write(str, len);
- return len;
+ return write(1, str, len);
}
void mp_hal_delay_ms(mp_uint_t ms) {