self.hu_struct_file_prefix = """
import CommonBase from './CommonBase.mjs';
import * as bindings from '../bindings.mjs'
+import * as InternalUtils from '../InternalUtils.mjs'
"""
self.c_fn_ty_pfx = ""
self.is_arr_some_check = ("", " != 0")
self.get_native_arr_len_call = ("", "->arr_len")
+ with open(outdir + "/InternalUtils.mts", "w") as f:
+ f.write("export function check_arr_len(arr: Uint8Array, len: number): Uint8Array {\n")
+ f.write("\tif (arr.length != len) { throw new Error(\"Expected array of length \" + len + \"got \" + arr.length); }\n")
+ f.write("\treturn arr;\n")
+ f.write("}")
+
def release_native_arr_ptr_call(self, ty_info, arr_var, arr_ptr_var):
return None
def create_native_arr_call(self, arr_len, ty_info):
def add_ref(self, holder, referent):
return "CommonBase.add_ref_from(" + holder + ", " + referent + ")"
+ def obj_defined(self, struct_names, folder):
+ with open(self.outdir + "/index.mts", 'a') as index:
+ index.write(f"export * from './{folder}/{struct_names[0]}.mjs';\n")
+ with open(self.outdir + "/imports.mts.part", 'a') as imports:
+ imports.write(f"import {{ {', '.join(struct_names)} }} from '../{folder}/{struct_names[0]}.mjs';\n")
+
def native_c_unitary_enum_map(self, struct_name, variants, enum_doc_comment):
out_c = "static inline LDK" + struct_name + " LDK" + struct_name + "_from_js(int32_t ord) {\n"
out_c = out_c + "\tswitch (ord) {\n"
}}
"""
out_typescript_enum = f"export {{ {struct_name} }} from \"../bindings.mjs\";"
+ self.obj_defined([struct_name], "enums")
return (out_c, out_typescript_enum, out_typescript)
def c_unitary_enum_to_native_call(self, ty_info):
out_c += ("\t}\n}\n")
out_java_enum += java_hu_class
self.struct_file_suffixes[java_hu_type] = java_hu_subclasses
+ self.obj_defined([java_hu_type], "structs")
return (out_java, out_java_enum, out_c)
def map_opaque_struct(self, struct_name, struct_doc_comment):
}}
"""
+ self.obj_defined([hu_name], "structs")
return out_opaque_struct_human
def map_tuple(self, struct_name):