[TS] Support mapping returned uint64[]s from rust functions
[ldk-java] / gen_type_mapping.py
index 0f2babf063690f50611db2ae53ba6c0d87f7e047..8dd7c6cafe452b09b52b91bb83ee91e6a3a5b446 100644 (file)
@@ -187,8 +187,6 @@ class TypeMappingGenerator:
                     if is_nullable:
                         ret_conv = (ret_conv[0], ret_conv[1] + "\n}")
 
-                to_hu_conv = None
-                to_hu_conv_name = None
                 if subty.to_hu_conv is not None:
                     to_hu_conv = self.consts.var_decl_statement(self.consts.c_type_map["uint32_t"][0], conv_name + "_len", self.consts.get_java_arr_len(arr_name)) + ";\n"
                     to_hu_conv += self.consts.var_decl_statement(ty_info.java_hu_ty, conv_name + "_arr", self.consts.constr_hu_array(ty_info, conv_name + "_len"))
@@ -200,6 +198,12 @@ class TypeMappingGenerator:
                     if cleanup is not None:
                         to_hu_conv += "\n" + cleanup
                     to_hu_conv_name = conv_name + "_arr"
+                else:
+                    to_hu_conv = self.consts.primitive_arr_to_hu(ty_info.subty, None, arr_name, arr_name + "_conv")
+                    if to_hu_conv is not None:
+                        to_hu_conv_name = arr_name + "_conv"
+                    else:
+                        to_hu_conv_name = None
                 from_hu_conv = self.consts.primitive_arr_from_hu(ty_info.subty, None, arr_name)
                 if subty.from_hu_conv is not None:
                     hu_conv_b = ""
@@ -504,10 +508,10 @@ class TypeMappingGenerator:
                         to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, ty_info.var_name + "_conv", "new " + ty_info.java_hu_ty + "(" + ty_info.var_name + ")") + ";",
                         to_hu_conv_name = ty_info.var_name + "_conv", from_hu_conv = ("0", ""))
 
-                if ty_info.rust_obj == "LDKu5":
+                if ty_info.rust_obj == "LDKu5" or ty_info.rust_obj == "LDKWitnessVersion":
                     assert from_hu_conv is None
                     return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
-                        arg_conv = "", arg_conv_name = "(LDKu5){ ._0 = " + ty_info.var_name + " }", arg_conv_cleanup = None,
+                        arg_conv = "", arg_conv_name = "(" + ty_info.rust_obj + "){ ._0 = " + ty_info.var_name + " }", arg_conv_cleanup = None,
                         ret_conv = ("uint8_t " + ty_info.var_name + "_val = ", "._0;"), ret_conv_name = ty_info.var_name + "_val",
                         to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, ty_info.var_name + "_conv", "new " + ty_info.java_hu_ty + "(" + ty_info.var_name + ")") + ";",
                         to_hu_conv_name = ty_info.var_name + "_conv", from_hu_conv = (ty_info.var_name + ".getVal()", ""))