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/objstr.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/objstr.c')
-rw-r--r-- | py/objstr.c | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/py/objstr.c b/py/objstr.c index 06bc98a723..14f32459d1 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -221,9 +221,7 @@ STATIC mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { GET_STR_DATA_LEN(lhs_in, lhs_data, lhs_len); switch (op) { case MP_BINARY_OP_SUBSCR: - // TODO: need predicate to check for int-like type (bools are such for example) - // ["no", "yes"][1 == 2] is common idiom - if (MP_OBJ_IS_SMALL_INT(rhs_in)) { + if (mp_obj_is_integer(rhs_in)) { uint index = mp_get_index(mp_obj_get_type(lhs_in), lhs_len, rhs_in, false); if (MP_OBJ_IS_TYPE(lhs_in, &mp_type_bytes)) { return MP_OBJ_NEW_SMALL_INT((mp_small_int_t)lhs_data[index]); |