Browse Source

unix/modjni: Add iteration support for Java List objects.

Using generic iteration-via-subscription support (TODO: factor it out for
reuse).
pull/1511/head
Paul Sokolovsky 9 years ago
parent
commit
fe29cc192d
  1. 15
      unix/modjni.c

15
unix/modjni.c

@ -274,6 +274,20 @@ STATIC mp_obj_t jobject_unary_op(mp_uint_t op, mp_obj_t self_in) {
}
}
// TODO: subscr_load_adaptor & subscr_getiter convenience functions
// should be moved to common location for reuse.
STATIC mp_obj_t subscr_load_adaptor(mp_obj_t self_in, mp_obj_t index_in) {
return mp_obj_subscr(self_in, index_in, MP_OBJ_SENTINEL);
}
MP_DEFINE_CONST_FUN_OBJ_2(subscr_load_adaptor_obj, subscr_load_adaptor);
// .getiter special method which returns iterator which works in terms
// of object subscription.
STATIC mp_obj_t subscr_getiter(mp_obj_t self_in) {
mp_obj_t dest[2] = {(mp_obj_t)&subscr_load_adaptor_obj, self_in};
return mp_obj_new_getitem_iter(dest);
}
STATIC const mp_obj_type_t jobject_type = {
{ &mp_type_type },
.name = MP_QSTR_jobject,
@ -281,6 +295,7 @@ STATIC const mp_obj_type_t jobject_type = {
.unary_op = jobject_unary_op,
.attr = jobject_attr,
.subscr = jobject_subscr,
.getiter = subscr_getiter,
// .locals_dict = (mp_obj_t)&jobject_locals_dict,
};

Loading…
Cancel
Save