summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-01-21 23:30:10 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-01-21 23:59:50 +0200
commit33996685dff97fc070a19d6f30dc61019b26016d (patch)
tree32a4efb2904bd1782759536786eb3e76c9c87cea /py
parent12eaccacda83a15500dae4616b3c37deecb57182 (diff)
downloadmicropython-33996685dff97fc070a19d6f30dc61019b26016d.tar.gz
micropython-33996685dff97fc070a19d6f30dc61019b26016d.zip
Add len() support for arrays.
Diffstat (limited to 'py')
-rw-r--r--py/obj.c2
-rw-r--r--py/obj.h1
-rw-r--r--py/objarray.c4
3 files changed, 7 insertions, 0 deletions
diff --git a/py/obj.c b/py/obj.c
index 8a073f4710..0291386144 100644
--- a/py/obj.c
+++ b/py/obj.c
@@ -285,6 +285,8 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) {
len = seq_len;
} else if (MP_OBJ_IS_TYPE(o_in, &dict_type)) {
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 {
return MP_OBJ_NULL;
}
diff --git a/py/obj.h b/py/obj.h
index c2ce32588a..e98cc552ec 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -334,6 +334,7 @@ extern const mp_obj_type_t zip_type;
// array
extern const mp_obj_type_t array_type;
+uint mp_obj_array_len(mp_obj_t self_in);
// functions
typedef struct _mp_obj_fun_native_t { // need this so we can define const objects (to go in ROM)
diff --git a/py/objarray.c b/py/objarray.c
index a054c8f980..cfab6eaa65 100644
--- a/py/objarray.c
+++ b/py/objarray.c
@@ -255,6 +255,10 @@ static mp_obj_array_t *array_new(char typecode, uint n) {
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_array_t *o = array_new(BYTEARRAY_TYPECODE, n);
memcpy(o->items, items, n);