Merge pull request #46 from TheBlueMatt/main
[ldk-java] / typescript_strings.py
index f90e5a60f761d0e0ceeb795b1a02cd58f33aa4b9..c097921f7d43de5ebc733be09392e1b24e19a6e4 100644 (file)
@@ -71,6 +71,8 @@ public static native long new_empty_slice_vec();
 
 """
 
+        self.bindings_version_file = ""
+
         self.bindings_footer = """
         export async function initializeWasm(allowDoubleInitialization: boolean = false): Promise<void> {
             if(isWasmInitialized && !allowDoubleInitialization) {
@@ -261,6 +263,8 @@ void __attribute__((visibility("default"))) TS_free(uint32_t ptr) {
 }
 """
 
+        self.c_version_file = ""
+
         self.hu_struct_file_prefix = f"""
 import CommonBase from './CommonBase';
 import * as bindings from '../bindings' // TODO: figure out location
@@ -272,6 +276,7 @@ import * as bindings from '../bindings' // TODO: figure out location
         self.ptr_native_ty = "number"
         self.result_c_ty = "uint32_t"
         self.ptr_arr = "ptrArray"
+        self.is_arr_some_check = ("", " != 0")
         self.get_native_arr_len_call = ("*((uint32_t*)", ")")
 
     def release_native_arr_ptr_call(self, ty_info, arr_var, arr_ptr_var):
@@ -719,10 +724,12 @@ const decodeString = (stringPointer, free = true) => {
                     out_c = out_c + "\t" + fn_line.ret_ty_info.c_ty + " ret = js_invoke_function_" + str(len(fn_line.args_ty)) + "(j_calls->" + fn_line.fn_name + "_meth"
                 elif fn_line.ret_ty_info.java_ty == "void":
                     out_c = out_c + "\tjs_invoke_function_" + str(len(fn_line.args_ty)) + "(j_calls->" + fn_line.fn_name + "_meth"
+                elif fn_line.ret_ty_info.java_ty == "String":
+                    out_c = out_c + "\tuint32_t ret = js_invoke_function_" + str(len(fn_line.args_ty)) + "(j_calls->" + fn_line.fn_name + "_meth"
                 elif not fn_line.ret_ty_info.passed_as_ptr:
                     out_c = out_c + "\treturn js_invoke_function_" + str(len(fn_line.args_ty)) + "(j_calls->" + fn_line.fn_name + "_meth"
                 else:
-                    out_c = out_c + "\t" + fn_line.ret_ty_info.rust_obj + "* ret = (" + fn_line.ret_ty_info.rust_obj + "*)js_invoke_function_" + str(len(fn_line.args_ty)) + "(j_calls->" + fn_line.fn_name + "_meth"
+                    out_c = out_c + "\tuint32_t ret = js_invoke_function_" + str(len(fn_line.args_ty)) + "(j_calls->" + fn_line.fn_name + "_meth"
 
                 for idx, arg_info in enumerate(fn_line.args_ty):
                     if arg_info.ret_conv is not None:
@@ -847,7 +854,7 @@ const decodeString = (stringPointer, free = true) => {
             init_meth_params = ""
             init_meth_body = ""
             hu_conv_body = ""
-            for idx, field_ty in enumerate(var.fields):
+            for idx, (field_ty, field_docs) in enumerate(var.fields):
                 out_java += ("\t\t\tpublic " + field_ty.java_ty + " " + field_ty.arg_name + ";\n")
                 java_hu_subclasses = java_hu_subclasses + "\tpublic " + field_ty.arg_name + f": {field_ty.java_hu_ty};\n"
                 if field_ty.to_hu_conv is not None:
@@ -880,7 +887,7 @@ const decodeString = (stringPointer, free = true) => {
         for var in variant_list:
             out_c += ("\t\tcase " + struct_name + "_" + var.var_name + ": {\n")
             c_params = []
-            for idx, field_map in enumerate(var.fields):
+            for idx, (field_map, _) in enumerate(var.fields):
                 if field_map.ret_conv is not None:
                     out_c += ("\t\t\t" + field_map.ret_conv[0].replace("\n", "\n\t\t\t"))
                     if var.tuple_variant:
@@ -932,7 +939,10 @@ const decodeString = (stringPointer, free = true) => {
 """
         return out_opaque_struct_human
 
-    def map_function(self, argument_types, c_call_string, method_name, return_type_info, struct_meth, default_constructor_args, takes_self, takes_self_as_ref, args_known, type_mapping_generator, doc_comment):
+    def map_tuple(self, struct_name):
+        return self.map_opaque_struct(struct_name, "A Tuple")
+
+    def map_function(self, argument_types, c_call_string, method_name, meth_n, return_type_info, struct_meth, default_constructor_args, takes_self, takes_self_as_ref, args_known, type_mapping_generator, doc_comment):
         out_java = ""
         out_c = ""
         out_java_struct = None
@@ -985,7 +995,6 @@ const decodeString = (stringPointer, free = true) => {
         if not args_known:
             out_java_struct += ("\t// Skipped " + method_name + "\n")
         else:
-            meth_n = method_name[len(struct_meth) + 1:]
             if not takes_self:
                 out_java_struct += (
                         "\tpublic static " + return_type_info.java_hu_ty + " constructor_" + meth_n + "(")