Commit 33996685 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

Add len() support for arrays.

parent 12eaccac
...@@ -285,6 +285,8 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) { ...@@ -285,6 +285,8 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) {
len = seq_len; len = seq_len;
} else if (MP_OBJ_IS_TYPE(o_in, &dict_type)) { } else if (MP_OBJ_IS_TYPE(o_in, &dict_type)) {
len = mp_obj_dict_len(o_in); len = mp_obj_dict_len(o_in);
} else if (MP_OBJ_IS_TYPE(o_in, &array_type)) {
len = mp_obj_array_len(o_in);
} else { } else {
return MP_OBJ_NULL; return MP_OBJ_NULL;
} }
......
...@@ -334,6 +334,7 @@ extern const mp_obj_type_t zip_type; ...@@ -334,6 +334,7 @@ extern const mp_obj_type_t zip_type;
// array // array
extern const mp_obj_type_t array_type; extern const mp_obj_type_t array_type;
uint mp_obj_array_len(mp_obj_t self_in);
// functions // functions
typedef struct _mp_obj_fun_native_t { // need this so we can define const objects (to go in ROM) typedef struct _mp_obj_fun_native_t { // need this so we can define const objects (to go in ROM)
......
...@@ -255,6 +255,10 @@ static mp_obj_array_t *array_new(char typecode, uint n) { ...@@ -255,6 +255,10 @@ static mp_obj_array_t *array_new(char typecode, uint n) {
return o; return o;
} }
uint mp_obj_array_len(mp_obj_t self_in) {
return ((mp_obj_array_t *)self_in)->len;
}
mp_obj_t mp_obj_new_bytearray(uint n, void *items) { mp_obj_t mp_obj_new_bytearray(uint n, void *items) {
mp_obj_array_t *o = array_new(BYTEARRAY_TYPECODE, n); mp_obj_array_t *o = array_new(BYTEARRAY_TYPECODE, n);
memcpy(o->items, items, n); memcpy(o->items, items, n);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment