]> git.bitcoin.ninja Git - ldk-java/commitdiff
map opaque struct header
authorArik Sosman <git@arik.io>
Sat, 16 Jan 2021 11:46:13 +0000 (03:46 -0800)
committerArik Sosman <git@arik.io>
Sat, 16 Jan 2021 11:46:13 +0000 (03:46 -0800)
genbindings.py
java_strings.py
typescript_strings.py

index 20c09fab9496340064defc9e75fb7edd6583d552..fa75b0fb44e5e8d646fd2630281c78ec6915a01f 100755 (executable)
@@ -919,20 +919,8 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java:
                 if is_opaque:
                     opaque_structs.add(struct_name)
                     with open(f"{sys.argv[3]}/structs/{struct_name.replace('LDK', '')}{consts.file_ext}", "w") as out_java_struct:
-                        out_java_struct.write(consts.hu_struct_file_prefix)
-                        out_java_struct.write("public class " + struct_name.replace("LDK","") + " extends CommonBase")
-                        if struct_name.startswith("LDKLocked"):
-                            out_java_struct.write(" implements AutoCloseable")
-                        out_java_struct.write(" {\n")
-                        out_java_struct.write("\t" + struct_name.replace("LDK", "") + "(Object _dummy, long ptr) { super(ptr); }\n")
-                        if struct_name.startswith("LDKLocked"):
-                            out_java_struct.write("\t@Override public void close() {\n")
-                        else:
-                            out_java_struct.write("\t@Override @SuppressWarnings(\"deprecation\")\n")
-                            out_java_struct.write("\tprotected void finalize() throws Throwable {\n")
-                            out_java_struct.write("\t\tsuper.finalize();\n")
-                        out_java_struct.write("\t\tif (ptr != 0) { bindings." + struct_name.replace("LDK","") + "_free(ptr); }\n")
-                        out_java_struct.write("\t}\n\n")
+                        out_opaque_struct_human = consts.map_opaque_struct(struct_name)
+                        out_java_struct.write(out_opaque_struct_human)
                 elif result_contents is not None:
                     assert result_contents in result_ptr_struct_items
                     res_ty, err_ty = result_ptr_struct_items[result_contents]
index 682169295aed2849375c7841d70b50e271fdc7fe..2e9ae67052d7d06fe6873065da9004d0a72fc4a2 100644 (file)
@@ -785,3 +785,21 @@ import java.util.Arrays;
         out_c += ("\t}\n}\n")
         out_java_enum += ("}\n")
         return (out_java, out_java_enum, out_c)
+
+    def map_opaque_struct(self, struct_name):
+        out_opaque_struct_human = ""
+        out_opaque_struct_human += self.hu_struct_file_prefix
+        out_opaque_struct_human += ("public class " + struct_name.replace("LDK","") + " extends CommonBase")
+        if struct_name.startswith("LDKLocked"):
+            out_opaque_struct_human += (" implements AutoCloseable")
+        out_opaque_struct_human += (" {\n")
+        out_opaque_struct_human += ("\t" + struct_name.replace("LDK", "") + "(Object _dummy, long ptr) { super(ptr); }\n")
+        if struct_name.startswith("LDKLocked"):
+            out_opaque_struct_human += ("\t@Override public void close() {\n")
+        else:
+            out_opaque_struct_human += ("\t@Override @SuppressWarnings(\"deprecation\")\n")
+            out_opaque_struct_human += ("\tprotected void finalize() throws Throwable {\n")
+            out_opaque_struct_human += ("\t\tsuper.finalize();\n")
+        out_opaque_struct_human += ("\t\tif (ptr != 0) { bindings." + struct_name.replace("LDK","") + "_free(ptr); }\n")
+        out_opaque_struct_human += ("\t}\n\n")
+        return out_opaque_struct_human
index 6a5815034c5a7d4853ee133f7a653a3aac5f6c5b..cbde654d453ae302847e8018fde36d1dbfebfc88 100644 (file)
@@ -726,3 +726,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