Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
b2d880d7
Commit
b2d880d7
authored
Sep 21, 2015
by
Paul Sokolovsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
unix/modjni: Support for subscripting of Java lists (r/o so far).
parent
6196aa45
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
0 deletions
+35
-0
unix/modjni.c
unix/modjni.c
+35
-0
No files found.
unix/modjni.c
View file @
b2d880d7
...
...
@@ -48,6 +48,10 @@ static jmethodID Class_getConstructors_mid;
static
jmethodID
Method_getName_mid
;
static
jmethodID
Method_toString_mid
;
static
jclass
List_class
;
static
jmethodID
List_get_mid
;
static
jmethodID
List_set_mid
;
STATIC
const
mp_obj_type_t
jobject_type
;
STATIC
const
mp_obj_type_t
jmethod_type
;
...
...
@@ -167,11 +171,36 @@ STATIC void jobject_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) {
}
}
STATIC
mp_obj_t
jobject_subscr
(
mp_obj_t
self_in
,
mp_obj_t
index
,
mp_obj_t
value
)
{
mp_obj_jobject_t
*
self
=
self_in
;
if
(
!
JJ
(
IsInstanceOf
,
self
->
obj
,
List_class
))
{
return
MP_OBJ_NULL
;
}
mp_uint_t
idx
=
mp_obj_get_int
(
index
);
if
(
value
==
MP_OBJ_NULL
)
{
// delete
assert
(
0
);
}
else
if
(
value
==
MP_OBJ_SENTINEL
)
{
// load
jobject
el
=
JJ
(
CallObjectMethod
,
self
->
obj
,
List_get_mid
,
idx
);
return
new_jobject
(
el
);
}
else
{
// store
assert
(
0
);
}
return
MP_OBJ_NULL
;
}
STATIC
const
mp_obj_type_t
jobject_type
=
{
{
&
mp_type_type
},
.
name
=
MP_QSTR_jobject
,
.
print
=
jobject_print
,
.
attr
=
jobject_attr
,
.
subscr
=
jobject_subscr
,
// .locals_dict = (mp_obj_t)&jobject_locals_dict,
};
...
...
@@ -414,6 +443,12 @@ STATIC void create_jvm() {
"()Ljava/lang/String;"
);
Method_toString_mid
=
(
*
env
)
->
GetMethodID
(
env
,
method_class
,
"toString"
,
"()Ljava/lang/String;"
);
List_class
=
JJ
(
FindClass
,
"java/util/List"
);
List_get_mid
=
JJ
(
GetMethodID
,
List_class
,
"get"
,
"(I)Ljava/lang/Object;"
);
List_set_mid
=
JJ
(
GetMethodID
,
List_class
,
"set"
,
"(ILjava/lang/Object;)Ljava/lang/Object;"
);
}
STATIC
mp_obj_t
mod_jni_cls
(
mp_obj_t
cls_name_in
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment