diff options
author | Damien George <damien.p.george@gmail.com> | 2014-04-09 19:55:33 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-04-09 19:55:33 +0100 |
commit | b5fbd0ba876b43d0f1d1d9af8dd556766bda553b (patch) | |
tree | 858468b318b2ad3f63c46add57796db729b003e7 /py/obj.c | |
parent | d99944acddbce627e96326551e47dbf5b3ef5800 (diff) | |
download | micropython-b5fbd0ba876b43d0f1d1d9af8dd556766bda553b.tar.gz micropython-b5fbd0ba876b43d0f1d1d9af8dd556766bda553b.zip |
py: Add mp_obj_is_integer; make mp_get_index check for long int.
mp_obj_is_integer should be used to check if an object is of integral
type. It returns true for bool, small int and long int.
Diffstat (limited to 'py/obj.c')
-rw-r--r-- | py/obj.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -99,6 +99,11 @@ int mp_obj_is_true(mp_obj_t arg) { } } +// returns true if o_in is bool, small int, or long int +bool mp_obj_is_integer(mp_obj_t o_in) { + return MP_OBJ_IS_INT(o_in) || MP_OBJ_IS_TYPE(o_in, &mp_type_bool); +} + bool mp_obj_is_callable(mp_obj_t o_in) { return mp_obj_get_type(o_in)->call != NULL; } @@ -285,8 +290,8 @@ void mp_obj_get_array_fixed_n(mp_obj_t o, uint len, mp_obj_t **items) { // is_slice determines whether the index is a slice index uint mp_get_index(const mp_obj_type_t *type, machine_uint_t len, mp_obj_t index, bool is_slice) { int i; - if (MP_OBJ_IS_SMALL_INT(index)) { - i = MP_OBJ_SMALL_INT_VALUE(index); + if (MP_OBJ_IS_INT(index)) { + i = mp_obj_int_get_checked(index); } else if (MP_OBJ_IS_TYPE(index, &mp_type_bool)) { i = (index == mp_const_true ? 1 : 0); } else { |