MCPcopy Create free account
hub / github.com/defold/defold / gen_from_jni_create_object

Function gen_from_jni_create_object

engine/jni/scripts/gen_java.py:903–1079  ·  view source on GitHub ↗
(decl, namespace, class_name, package_name, header=False)

Source from the content-addressed store, hash-verified

901 l(f'}}')
902
903def gen_from_jni_create_object(decl, namespace, class_name, package_name, header=False):
904 struct_name = decl["name"]
905
906 fn = f'bool J2C_Create{struct_name}(JNIEnv* env, TypeInfos* types, jobject obj, {struct_name}* out)'
907 if header:
908 l(f'{fn};')
909 return
910
911 l(f'{fn} {{')
912 l(f' if (out == 0) return false;')
913
914 for field in decl['fields']:
915 field_name = check_override(field['name'])
916
917 jni_field_name = to_jni_camel_case(field_name, 'm_')
918 field_type = check_override(f'{struct_name}.{field_name}', default=field['type'])
919
920 namespace_prefix = f"{namespace}::"
921 field_type = field_type.replace(namespace_prefix, '')
922
923 field_id = f'types->m_{struct_name}JNI.{jni_field_name}'
924
925 # https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html#Set_type_Field_routines
926 if is_prim_type(field_type):
927 jni_type = c_type_to_jni_capname.get(field_type, None)
928
929 if field_name.endswith('Count') and has_array(decl['fields'], namespace, field_name.replace('Count', '')):
930 continue
931
932 if jni_type is not None:
933 l(f' out->{field_name} = dmJNI::Get{jni_type}(env, obj, {field_id});')
934 elif is_struct_type(field_type):
935 l(f' {{')
936 l(f' jobject field_object = env->GetObjectField(obj, {field_id});')
937 l(f' if (field_object) {{')
938 l(f' J2C_Create{field_type}(env, types, field_object, &out->{field_name});')
939 l(f' env->DeleteLocalRef(field_object);')
940 l(f' }}')
941 l(f' }}')
942
943 elif is_enum_type(field_type):
944 l(f' out->{field_name} = ({field_type})dmJNI::GetEnum(env, obj, {field_id});')
945
946 elif util.is_string_ptr(field_type):
947 l(f' out->{field_name} = dmJNI::GetString(env, obj, {field_id});')
948 elif util.is_const_void_ptr(field_type):
949 l(f' out->{field_name} = (const void*)(uintptr_t)dmJNI::GetLong(env, obj, {field_id});')
950 elif util.is_void_ptr(field_type):
951 l(f' out->{field_name} = (void*)(uintptr_t)dmJNI::GetLong(env, obj, {field_id});')
952
953 elif util.is_dmarray_type(field_type):
954
955 field_type = util.extract_dmarray_type(field_type)
956 c_type, ptr = util.extract_ptr_type2(field_type)
957
958 jni_typestr = c_type_to_jni_capname.get(field_type, None)
959 jni_type = c_type_to_jni_type.get(field_type, None)
960 jni_field_name = to_jni_camel_case(field_name, 'm_')

Callers 1

gen_jni_namespace_sourceFunction · 0.85

Calls 13

check_overrideFunction · 0.85
to_jni_camel_caseFunction · 0.85
is_prim_typeFunction · 0.85
has_arrayFunction · 0.85
is_struct_typeFunction · 0.85
is_enum_typeFunction · 0.85
is_prim_ptrFunction · 0.85
is_struct_ptrFunction · 0.85
get_array_count_fieldFunction · 0.85
replaceMethod · 0.80
lFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected