From: Arik Sosman Date: Sat, 16 Jan 2021 11:46:13 +0000 (-0800) Subject: map opaque struct header X-Git-Tag: v0.0.1~42 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=ba97d8dee5ef43b8b61c9a61e30789cdf8eb9c5e;p=ldk-java map opaque struct header --- diff --git a/genbindings.py b/genbindings.py index 20c09fab..fa75b0fb 100755 --- a/genbindings.py +++ b/genbindings.py @@ -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] diff --git a/java_strings.py b/java_strings.py index 68216929..2e9ae670 100644 --- a/java_strings.py +++ b/java_strings.py @@ -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 diff --git a/typescript_strings.py b/typescript_strings.py index 6a581503..cbde654d 100644 --- a/typescript_strings.py +++ b/typescript_strings.py @@ -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