diff options
| author | blmorris <bryan.morrissey@gmail.com> | 2014-07-21 12:47:57 -0400 |
|---|---|---|
| committer | blmorris <bryan.morrissey@gmail.com> | 2014-07-21 12:47:57 -0400 |
| commit | 4038f513ea0a6be75ecbc4d8ab2bbe2349524bca (patch) | |
| tree | 2aace8a3551d5c397ec539865bbb2f6cdbc8d900 /py/builtin.c | |
| parent | 0f4ee2e44a1e47258a8b07fb25e28286d131390c (diff) | |
| parent | 951ed9d02ffc826c68ee3af26c3530477e7e6156 (diff) | |
Merge https://github.com/micropython/micropython
Diffstat (limited to 'py/builtin.c')
| -rw-r--r-- | py/builtin.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/py/builtin.c b/py/builtin.c index e723fad33..725613385 100644 --- a/py/builtin.c +++ b/py/builtin.c @@ -36,6 +36,8 @@ #include "runtime0.h" #include "runtime.h" #include "builtin.h" +#include "stream.h" +#include "pfenv.h" #if MICROPY_PY_BUILTINS_FLOAT #include <math.h> @@ -424,13 +426,36 @@ STATIC mp_obj_t mp_builtin_print(uint n_args, const mp_obj_t *args, mp_map_t *kw if (end_elem != NULL && end_elem->value != mp_const_none) { end_data = mp_obj_str_get_data(end_elem->value, &end_len); } + #if MICROPY_PY_IO + mp_obj_t stream_obj = &mp_sys_stdout_obj; + mp_map_elem_t *file_elem = mp_map_lookup(kwargs, MP_OBJ_NEW_QSTR(MP_QSTR_file), MP_MAP_LOOKUP); + if (file_elem != NULL && file_elem->value != mp_const_none) { + stream_obj = file_elem->value; + } + + pfenv_t pfenv; + pfenv.data = stream_obj; + pfenv.print_strn = (void (*)(void *, const char *, unsigned int))mp_stream_write; + #endif for (int i = 0; i < n_args; i++) { if (i > 0) { + #if MICROPY_PY_IO + mp_stream_write(stream_obj, sep_data, sep_len); + #else printf("%.*s", sep_len, sep_data); + #endif } + #if MICROPY_PY_IO + mp_obj_print_helper((void (*)(void *env, const char *fmt, ...))pfenv_printf, &pfenv, args[i], PRINT_STR); + #else mp_obj_print(args[i], PRINT_STR); + #endif } + #if MICROPY_PY_IO + mp_stream_write(stream_obj, end_data, end_len); + #else printf("%.*s", end_len, end_data); + #endif return mp_const_none; } |
