diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-09-18 13:37:40 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-09-18 13:37:40 +0300 |
commit | 5bf1b4e9d9d563887d10c5ee9dceef9567679819 (patch) | |
tree | ab3106c3a1dce43f88ed61384b3f6f5447b290bc | |
parent | d08c9d342fe864679bab04891f4b8907a4c659d0 (diff) | |
download | micropython-5bf1b4e9d9d563887d10c5ee9dceef9567679819.tar.gz micropython-5bf1b4e9d9d563887d10c5ee9dceef9567679819.zip |
unix/modjni: array(): Support creation of object arrays.
-rw-r--r-- | unix/modjni.c | 64 |
1 files changed, 36 insertions, 28 deletions
diff --git a/unix/modjni.c b/unix/modjni.c index 5d1de17f5d..c06e68eaa5 100644 --- a/unix/modjni.c +++ b/unix/modjni.c @@ -655,38 +655,46 @@ STATIC mp_obj_t mod_jni_cls(mp_obj_t cls_name_in) { MP_DEFINE_CONST_FUN_OBJ_1(mod_jni_cls_obj, mod_jni_cls); STATIC mp_obj_t mod_jni_array(mp_obj_t type_in, mp_obj_t size_in) { - const char *type = mp_obj_str_get_str(type_in); - mp_int_t size = mp_obj_get_int(size_in); if (!env) { create_jvm(); } - + mp_int_t size = mp_obj_get_int(size_in); jobject res = NULL; - switch (*type) { - case 'Z': - res = JJ(NewBooleanArray, size); - break; - case 'B': - res = JJ(NewByteArray, size); - break; - case 'C': - res = JJ(NewCharArray, size); - break; - case 'S': - res = JJ(NewShortArray, size); - break; - case 'I': - res = JJ(NewIntArray, size); - break; - case 'J': - res = JJ(NewLongArray, size); - break; - case 'F': - res = JJ(NewFloatArray, size); - break; - case 'D': - res = JJ(NewDoubleArray, size); - break; + + if (MP_OBJ_IS_TYPE(type_in, &jclass_type)) { + + mp_obj_jclass_t *jcls = type_in; + res = JJ(NewObjectArray, size, jcls->cls, NULL); + + } else if (MP_OBJ_IS_STR(type_in)) { + const char *type = mp_obj_str_get_str(type_in); + switch (*type) { + case 'Z': + res = JJ(NewBooleanArray, size); + break; + case 'B': + res = JJ(NewByteArray, size); + break; + case 'C': + res = JJ(NewCharArray, size); + break; + case 'S': + res = JJ(NewShortArray, size); + break; + case 'I': + res = JJ(NewIntArray, size); + break; + case 'J': + res = JJ(NewLongArray, size); + break; + case 'F': + res = JJ(NewFloatArray, size); + break; + case 'D': + res = JJ(NewDoubleArray, size); + break; + } + } return new_jobject(res); |