Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fe29cc1

Browse filesBrowse files
committed
unix/modjni: Add iteration support for Java List objects.
Using generic iteration-via-subscription support (TODO: factor it out for reuse).
1 parent 41eb705 commit fe29cc1
Copy full SHA for fe29cc1

1 file changed

+15Lines changed: 15 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎unix/modjni.c‎

Copy file name to clipboardExpand all lines: unix/modjni.c
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,28 @@ STATIC mp_obj_t jobject_unary_op(mp_uint_t op, mp_obj_t self_in) {
274274
}
275275
}
276276

277+
// TODO: subscr_load_adaptor & subscr_getiter convenience functions
278+
// should be moved to common location for reuse.
279+
STATIC mp_obj_t subscr_load_adaptor(mp_obj_t self_in, mp_obj_t index_in) {
280+
return mp_obj_subscr(self_in, index_in, MP_OBJ_SENTINEL);
281+
}
282+
MP_DEFINE_CONST_FUN_OBJ_2(subscr_load_adaptor_obj, subscr_load_adaptor);
283+
284+
// .getiter special method which returns iterator which works in terms
285+
// of object subscription.
286+
STATIC mp_obj_t subscr_getiter(mp_obj_t self_in) {
287+
mp_obj_t dest[2] = {(mp_obj_t)&subscr_load_adaptor_obj, self_in};
288+
return mp_obj_new_getitem_iter(dest);
289+
}
290+
277291
STATIC const mp_obj_type_t jobject_type = {
278292
{ &mp_type_type },
279293
.name = MP_QSTR_jobject,
280294
.print = jobject_print,
281295
.unary_op = jobject_unary_op,
282296
.attr = jobject_attr,
283297
.subscr = jobject_subscr,
298+
.getiter = subscr_getiter,
284299
// .locals_dict = (mp_obj_t)&jobject_locals_dict,
285300
};
286301

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.