+ def get_java_arr_len(self, arr_name):
+ return "bindings.getArrayLength(" + arr_name + ")"
+ def get_java_arr_elem(self, elem_ty, arr_name, idx):
+ if elem_ty.c_ty == "uint32_t" or elem_ty.c_ty == "uintptr_t" or elem_ty.c_ty.endswith("Array"):
+ return "bindings.getU32ArrayElem(" + arr_name + ", " + idx + ")"
+ else:
+ assert False
+ def constr_hu_array(self, ty_info, arr_len):
+ return "new Array(" + arr_len + ").fill(null)"
+
+ def primitive_arr_from_hu(self, mapped_ty, fixed_len, arr_name):
+ inner = arr_name
+ if fixed_len is not None:
+ assert mapped_ty.c_ty == "int8_t"
+ inner = "bindings.check_arr_len(" + arr_name + ", " + fixed_len + ")"
+ if mapped_ty.c_ty.endswith("Array"):
+ return ("bindings.encodeUint32Array(" + inner + ")", "")
+ elif mapped_ty.c_ty == "uint8_t" or mapped_ty.c_ty == "int8_t":
+ return ("bindings.encodeUint8Array(" + inner + ")", "")
+ elif mapped_ty.c_ty == "uint32_t":
+ return ("bindings.encodeUint32Array(" + inner + ")", "")
+ elif mapped_ty.c_ty == "int64_t":
+ return ("bindings.encodeUint64Array(" + inner + ")", "")
+ else:
+ print(mapped_ty.c_ty)
+ assert False
+
+ def primitive_arr_to_hu(self, mapped_ty, fixed_len, arr_name, conv_name):
+ assert mapped_ty.c_ty == "uint8_t" or mapped_ty.c_ty == "int8_t"
+ return "const " + conv_name + ": Uint8Array = bindings.decodeUint8Array(" + arr_name + ");"
+
+ def var_decl_statement(self, ty_string, var_name, statement):
+ return "const " + var_name + ": " + ty_string + " = " + statement
+
+ def java_arr_ty_str(self, elem_ty_str):
+ return "number"
+
+ def for_n_in_range(self, n, minimum, maximum):
+ return "for (var " + n + " = " + minimum + "; " + n + " < " + maximum + "; " + n + "++) {"
+ def for_n_in_arr(self, n, arr_name, arr_elem_ty):
+ return (arr_name + ".forEach((" + n + ": " + arr_elem_ty.java_hu_ty + ") => { ", " })")
+
+ def get_ptr(self, var):
+ return "CommonBase.get_ptr_of(" + var + ")"
+ def set_null_skip_free(self, var):
+ return "CommonBase.set_null_skip_free(" + var + ");"
+
+ 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"