]> git.bitcoin.ninja Git - ldk-java/commitdiff
Make human -> C array mapping language-specific
authorMatt Corallo <git@bluematt.me>
Fri, 7 Jan 2022 20:59:42 +0000 (20:59 +0000)
committerMatt Corallo <git@bluematt.me>
Sat, 8 Jan 2022 04:06:53 +0000 (04:06 +0000)
gen_type_mapping.py
java_strings.py
typescript_strings.py

index f4d6b380476337e0c2df21dda5558a0fbf505211..76510119d4fa63af06ecb4978bee3e5abebe24cc 100644 (file)
@@ -198,14 +198,7 @@ class TypeMappingGenerator:
                     hu_conv_b = ""
                     if subty.from_hu_conv[1] != "":
                         hu_conv_b = "for (" + subty.java_hu_ty + " " + conv_name + ": " + arr_name + ") { " + subty.from_hu_conv[1] + "; }"
-                    if subty.java_ty == "long" and subty.java_hu_ty != "long":
-                        from_hu_conv = (arr_name + " != null ? Arrays.stream(" + arr_name + ").mapToLong(" + conv_name + " -> " + subty.from_hu_conv[0] + ").toArray() : null",
-                            hu_conv_b)
-                    elif subty.java_ty == "long":
-                        from_hu_conv = (arr_name + " != null ? Arrays.stream(" + arr_name + ").map(" + conv_name + " -> " + subty.from_hu_conv[0] + ").toArray() : null", "/* TODO 2 " + subty.java_hu_ty + "  */")
-                    else:
-                        from_hu_conv = (arr_name + " != null ? Arrays.stream(" + arr_name + ").map(" + conv_name + " -> " + subty.from_hu_conv[0] + ").toArray(" + ty_info.java_ty + "::new) : null",
-                            hu_conv_b)
+                    from_hu_conv = (self.consts.map_hu_array_elems(arr_name, conv_name, ty_info, subty), hu_conv_b)
 
                 return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
                     arg_conv = arg_conv, arg_conv_name = arg_conv_name, arg_conv_cleanup = arg_conv_cleanup,
index ada526fcbaa512952d4fdd7b172c6a3a77201767..cb23b56a6d01332e8e25a8c8de0dc56fab45ae95 100644 (file)
@@ -595,6 +595,14 @@ import javax.annotation.Nullable;
         else:
             return "(*env)->Release" + ty_info.java_ty.strip("[]").title() + "ArrayElements(env, " + arr_name + ", " + dest_name + ", 0)"
 
+    def map_hu_array_elems(self, arr_name, conv_name, arr_ty, elem_ty):
+        if elem_ty.java_ty == "long" and elem_ty.java_hu_ty != "long":
+            return arr_name + " != null ? Arrays.stream(" + arr_name + ").mapToLong(" + conv_name + " -> " + elem_ty.from_hu_conv[0] + ").toArray() : null"
+        elif elem_ty.java_ty == "long":
+            return arr_name + " != null ? Arrays.stream(" + arr_name + ").map(" + conv_name + " -> " + elem_ty.from_hu_conv[0] + ").toArray() : null"
+        else:
+            return arr_name + " != null ? Arrays.stream(" + arr_name + ").map(" + conv_name + " -> " + elem_ty.from_hu_conv[0] + ").toArray(" + arr_ty.java_ty + "::new) : null"
+
     def str_ref_to_native_call(self, var_name, str_len):
         return "str_ref_to_java(env, " + var_name + ", " + str_len + ")"
     def str_ref_to_c_call(self, var_name):
index faa13d572d623a6b09d4dbba495ba473b5692203..01096343e7d86d7d1acafcff0c0d0da9127170a8 100644 (file)
@@ -358,6 +358,9 @@ import * as InternalUtils from '../InternalUtils.mjs'
         else:
             return None
 
+    def map_hu_array_elems(self, arr_name, conv_name, arr_ty, elem_ty):
+        return arr_name + " != null ? " + arr_name + ".map(" + conv_name + " => " + elem_ty.from_hu_conv[0] + ") : null"
+
     def str_ref_to_native_call(self, var_name, str_len):
         return "str_ref_to_ts(" + var_name + ", " + str_len + ")"
     def str_ref_to_c_call(self, var_name):