Add RAW_ARRAY as valid paramter for java binding

This commit is contained in:
marynate 2014-06-04 11:32:49 +08:00
parent 6f0b4678e2
commit 57a53fbe52
1 changed files with 23 additions and 0 deletions

View File

@ -152,6 +152,14 @@ jvalue _variant_to_jvalue(JNIEnv *env, Variant::Type p_type, const Variant* p_ar
env->SetIntArrayRegion(arr,0,array.size(),r.ptr());
v.l=arr;
} break;
case Variant::RAW_ARRAY: {
DVector<uint8_t> array = *p_arg;
jbyteArray arr = env->NewByteArray(array.size());
DVector<uint8_t>::Read r = array.read();
env->SetByteArrayRegion(arr,0,array.size(),reinterpret_cast<const signed char*>(r.ptr()));
v.l=arr;
} break;
case Variant::REAL_ARRAY: {
@ -244,6 +252,19 @@ Variant _jobject_to_variant(JNIEnv * env, jobject obj) {
return sarr;
};
if (name == "[B") {
jbyteArray arr = (jbyteArray)obj;
int fCount = env->GetArrayLength(arr);
DVector<uint8_t> sarr;
sarr.resize(fCount);
DVector<uint8_t>::Write w = sarr.write();
env->GetByteArrayRegion(arr,0,fCount,reinterpret_cast<signed char*>(w.ptr()));
w = DVector<uint8_t>::Write();
return sarr;
};
if (name == "java.lang.Float" || name == "java.lang.Double") {
jclass nclass = env->FindClass("java/lang/Number");
@ -1346,6 +1367,7 @@ static Variant::Type get_jni_type(const String& p_type) {
{"double", Variant::REAL},
{"java.lang.String",Variant::STRING},
{"[I",Variant::INT_ARRAY},
{"[B",Variant::RAW_ARRAY},
{"[F",Variant::REAL_ARRAY},
{"[java.lang.String",Variant::STRING_ARRAY},
{"com.android.godot.Dictionary", Variant::DICTIONARY},
@ -1381,6 +1403,7 @@ static const char* get_jni_sig(const String& p_type) {
{"java.lang.String","Ljava/lang/String;"},
{"com.android.godot.Dictionary", "Lcom/android/godot/Dictionary;"},
{"[I","[I"},
{"[B","[B"},
{"[F","[F"},
{"[java.lang.String","[Ljava/lang/String;"},
{NULL,"V"}