unix/modjni: array(): Support creation of object arrays.
This commit is contained in:
parent
d08c9d342f
commit
5bf1b4e9d9
@ -655,13 +655,19 @@ 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);
|
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) {
|
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) {
|
if (!env) {
|
||||||
create_jvm();
|
create_jvm();
|
||||||
}
|
}
|
||||||
|
mp_int_t size = mp_obj_get_int(size_in);
|
||||||
jobject res = NULL;
|
jobject res = NULL;
|
||||||
|
|
||||||
|
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) {
|
switch (*type) {
|
||||||
case 'Z':
|
case 'Z':
|
||||||
res = JJ(NewBooleanArray, size);
|
res = JJ(NewBooleanArray, size);
|
||||||
@ -689,6 +695,8 @@ STATIC mp_obj_t mod_jni_array(mp_obj_t type_in, mp_obj_t size_in) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return new_jobject(res);
|
return new_jobject(res);
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_2(mod_jni_array_obj, mod_jni_array);
|
MP_DEFINE_CONST_FUN_OBJ_2(mod_jni_array_obj, mod_jni_array);
|
||||||
|
Loading…
Reference in New Issue
Block a user