py: Add native json printing using existing print framework.
Also add start of ujson module with dumps implemented. Enabled in unix and stmhal ports. Test passes on both.
This commit is contained in:
@@ -49,12 +49,15 @@ STATIC mp_obj_t list_pop(mp_uint_t n_args, const mp_obj_t *args);
|
||||
|
||||
STATIC void list_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
|
||||
mp_obj_list_t *o = o_in;
|
||||
if (!(MICROPY_PY_UJSON && kind == PRINT_JSON)) {
|
||||
kind = PRINT_REPR;
|
||||
}
|
||||
print(env, "[");
|
||||
for (mp_uint_t i = 0; i < o->len; i++) {
|
||||
if (i > 0) {
|
||||
print(env, ", ");
|
||||
}
|
||||
mp_obj_print_helper(print, env, o->items[i], PRINT_REPR);
|
||||
mp_obj_print_helper(print, env, o->items[i], kind);
|
||||
}
|
||||
print(env, "]");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user