Fix short, push trait struct refcnt increment down to lang
[ldk-java] / typescript_strings.py
index 6a5815034c5a7d4853ee133f7a653a3aac5f6c5b..7c6e6ab5644b5abb99d926b5d527bb803957f531 100644 (file)
@@ -214,7 +214,7 @@ import * as bindings from '../bindings' // TODO: figure out location
         self.c_fn_args_pfx = "void* ctx_TODO"
         self.file_ext = ".ts"
         self.ptr_c_ty = "uint32_t"
-        self.ptr_native_ty = "uint32_t"
+        self.ptr_native_ty = "number" # "uint32_t"
         self.result_c_ty = "uint32_t"
         self.ptr_arr = "uint32_tArray"
         self.get_native_arr_len_call = ("", ".len")
@@ -650,6 +650,9 @@ const wasm = wasmInstance.exports;
 
         return (out_typescript_bindings, out_typescript_human, out_c)
 
+    def trait_struct_inc_refcnt(self, ty_info):
+        return ""
+
     def map_complex_enum(self, struct_name, variant_list, camel_to_snake):
         java_hu_type = struct_name.replace("LDK", "")
 
@@ -726,3 +729,34 @@ const wasm = wasmInstance.exports;
         out_java_enum += ("}\n")
         out_java_enum += (java_hu_subclasses)
         return (out_java, out_java_enum, out_c)
+
+    def map_opaque_struct(self, struct_name):
+
+        implementations = ""
+        method_header = ""
+        if struct_name.startswith("LDKLocked"):
+            implementations += "implements AutoCloseable "
+            method_header = """
+                public close() {
+            """
+        else:
+            method_header = """
+                protected finalize() {
+                    super.finalize();
+            """
+
+        out_opaque_struct_human = f"""
+            {self.hu_struct_file_prefix}
+            
+            export default class {struct_name.replace("LDK","")} extends CommonBase {implementations}{{
+                constructor(_dummy: object, ptr: number) {{
+                    super(ptr);
+                }}
+                
+                {method_header}
+                    if (this.ptr != 0) {{
+                        bindings.{struct_name.replace("LDK","")}_free(this.ptr);
+                    }}
+                }}
+        """
+        return out_opaque_struct_human