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]
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
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