diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-02-10 06:42:20 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-02-10 07:13:32 +0200 |
commit | 624eff6a8a948c5ffa7c7d17fab69b3739f2e711 (patch) | |
tree | c650395f4cd9c4a42e7c714f04bee5d65497cac9 /py/objtuple.c | |
parent | 0cd1dc06e673e86058eb14cdd7ae6622cb57fde5 (diff) | |
download | micropython-624eff6a8a948c5ffa7c7d17fab69b3739f2e711.tar.gz micropython-624eff6a8a948c5ffa7c7d17fab69b3739f2e711.zip |
Implement tuple.index().
Diffstat (limited to 'py/objtuple.c')
-rw-r--r-- | py/objtuple.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/py/objtuple.c b/py/objtuple.c index 18eb6df4de..581bfb6290 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -153,6 +153,18 @@ static mp_obj_t tuple_getiter(mp_obj_t o_in) { return mp_obj_new_tuple_iterator(o_in, 0); } +static mp_obj_t tuple_index(uint n_args, const mp_obj_t *args) { + assert(MP_OBJ_IS_TYPE(args[0], &tuple_type)); + mp_obj_tuple_t *self = args[0]; + return mp_seq_index_obj(self->items, self->len, n_args, args); +} +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(tuple_index_obj, 2, 4, tuple_index); + +static const mp_method_t tuple_type_methods[] = { + { "index", &tuple_index_obj }, + { NULL, NULL }, // end-of-list sentinel +}; + const mp_obj_type_t tuple_type = { { &mp_const_type }, "tuple", @@ -161,6 +173,7 @@ const mp_obj_type_t tuple_type = { .unary_op = tuple_unary_op, .binary_op = tuple_binary_op, .getiter = tuple_getiter, + .methods = tuple_type_methods, }; // the zero-length tuple |