diff options
author | John R. Lenton <jlenton@gmail.com> | 2014-01-06 17:38:47 +0000 |
---|---|---|
committer | John R. Lenton <jlenton@gmail.com> | 2014-01-07 22:51:08 +0000 |
commit | 4ce6ceadcad294a62f6fb2b23da262dc5cad0793 (patch) | |
tree | 43d36b56d44ba873988ef498b71026646f4c135f /py/objdict.c | |
parent | a41fe31322e92f84ecee4f3e6295bed2ec9120fd (diff) | |
download | micropython-4ce6ceadcad294a62f6fb2b23da262dc5cad0793.tar.gz micropython-4ce6ceadcad294a62f6fb2b23da262dc5cad0793.zip |
Added dict.clear.
Added 0 to the list of primes. Funky primes, these.
Diffstat (limited to 'py/objdict.c')
-rw-r--r-- | py/objdict.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/py/objdict.c b/py/objdict.c index 4cd6363796..1a5e162e56 100644 --- a/py/objdict.c +++ b/py/objdict.c @@ -120,9 +120,20 @@ static mp_obj_t dict_getiter(mp_obj_t o_in) { /******************************************************************************/ /* dict methods */ +static mp_obj_t dict_clear(mp_obj_t self_in) { + assert(MP_OBJ_IS_TYPE(self_in, &dict_type)); + mp_obj_dict_t *self = self_in; + + mp_map_clear(&self->map); + + return mp_const_none; +} + /******************************************************************************/ /* dict constructors & etc */ +static MP_DEFINE_CONST_FUN_OBJ_1(dict_clear_obj, dict_clear); + const mp_obj_type_t dict_type = { { &mp_const_type }, "dict", @@ -130,7 +141,10 @@ const mp_obj_type_t dict_type = { .make_new = dict_make_new, .binary_op = dict_binary_op, .getiter = dict_getiter, - .methods = {{NULL, NULL},}, + .methods = { + { "clear", &dict_clear_obj }, + { NULL, NULL }, // end-of-list sentinel + }, }; mp_obj_t mp_obj_new_dict(int n_args) { |