can_clone = False
out_java.write("\tpublic static native boolean " + struct_name + "_result_ok(long arg);\n")
- write_c(consts.c_fn_ty_pfx + "jboolean " + consts.c_fn_name_pfx + struct_name.replace("_", "_1") + "_1result_1ok (" + consts.c_fn_args_pfx + ", " + consts.ptr_c_ty + " arg) {\n")
+ write_c(consts.c_fn_ty_pfx + "jboolean " + consts.c_fn_name_define_pfx(struct_name + "_result_ok", True) + consts.ptr_c_ty + " arg) {\n")
write_c("\treturn ((" + struct_name + "*)arg)->result_ok;\n")
write_c("}\n")
out_java.write("\tpublic static native " + res_map.java_ty + " " + struct_name + "_get_ok(long arg);\n")
- write_c(consts.c_fn_ty_pfx + res_map.c_ty + " " + consts.c_fn_name_pfx + struct_name.replace("_", "_1") + "_1get_1ok (" + consts.c_fn_args_pfx + ", " + consts.ptr_c_ty + " arg) {\n")
+ write_c(consts.c_fn_ty_pfx + res_map.c_ty + " " + consts.c_fn_name_define_pfx(struct_name + "_get_ok", True) + consts.ptr_c_ty + " arg) {\n")
write_c("\t" + struct_name + " *val = (" + struct_name + "*)arg;\n")
write_c("\tCHECK(val->result_ok);\n\t")
out_java_struct.write("\tpublic static final class " + human_ty + "_OK extends " + human_ty + " {\n")
out_java_struct.write("\t\t}\n\t}\n\n")
out_java.write("\tpublic static native " + err_map.java_ty + " " + struct_name + "_get_err(long arg);\n")
- write_c(consts.c_fn_ty_pfx + err_map.c_ty + " " + consts.c_fn_name_pfx + struct_name.replace("_", "_1") + "_1get_1err (" + consts.c_fn_args_pfx + ", " + consts.ptr_c_ty + " arg) {\n")
+ write_c(consts.c_fn_ty_pfx + err_map.c_ty + " " + consts.c_fn_name_define_pfx(struct_name + "_get_err", True) + consts.ptr_c_ty + " arg) {\n")
write_c("\t" + struct_name + " *val = (" + struct_name + "*)arg;\n")
write_c("\tCHECK(!val->result_ok);\n\t")
out_java_struct.write("\tpublic static final class " + human_ty + "_Err extends " + human_ty + " {\n")
def map_tuple(struct_name, field_lines):
out_java.write("\tpublic static native long " + struct_name + "_new(")
- write_c(consts.c_fn_ty_pfx + consts.ptr_c_ty + " " + consts.c_fn_name_pfx + struct_name.replace("_", "_1") + "_1new(" + consts.c_fn_args_pfx)
+ write_c(consts.c_fn_ty_pfx + consts.ptr_c_ty + " " + consts.c_fn_name_define_pfx(struct_name + "_new", len(field_lines) > 3))
ty_list = []
for idx, line in enumerate(field_lines):
if idx != 0 and idx < len(field_lines) - 2:
ty_info = java_c_types(line.strip(';'), None)
if idx != 1:
out_java.write(", ")
+ write_c(", ")
e = chr(ord('a') + idx - 1)
out_java.write(ty_info.java_ty + " " + e)
- write_c(", " + ty_info.c_ty + " " + e)
+ write_c(ty_info.c_ty + " " + e)
ty_list.append(ty_info)
tuple_types[struct_name] = (ty_list, struct_name)
out_java.write(");\n")
for idx, ty_info in enumerate(ty_list):
e = chr(ord('a') + idx)
out_java.write("\tpublic static native " + ty_info.java_ty + " " + struct_name + "_get_" + e + "(long ptr);\n")
- write_c(consts.c_fn_ty_pfx + ty_info.c_ty + " " + consts.c_fn_name_pfx + struct_name.replace("_", "_1") + "_1get_1" + e + "(" + consts.c_fn_args_pfx + ", " + consts.ptr_c_ty + " ptr) {\n")
+ write_c(consts.c_fn_ty_pfx + ty_info.c_ty + " " + consts.c_fn_name_define_pfx(struct_name + "_get_" + e, True) + consts.ptr_c_ty + " ptr) {\n")
write_c("\t" + struct_name + " *tuple = (" + struct_name + "*)ptr;\n")
conv_info = type_mapping_generator.map_type_with_info(ty_info, False, None, False, True)
if conv_info.ret_conv is not None:
ty_info = type_mapping_generator.map_type(vec_ty + " arr_elem", False, None, False, False)
if len(ty_info.java_fn_ty_arg) == 1: # ie we're a primitive of some form
out_java.write("\tpublic static native long " + struct_name + "_new(" + ty_info.java_ty + "[] elems);\n")
- write_c(consts.c_fn_ty_pfx + consts.ptr_c_ty + " " + consts.c_fn_name_pfx + struct_name.replace("_", "_1") + "_1new(" + consts.c_fn_args_pfx + ", " + ty_info.c_ty + "Array elems) {\n")
+ write_c(consts.c_fn_ty_pfx + consts.ptr_c_ty + " " + consts.c_fn_name_define_pfx(struct_name + "_new", True) + ty_info.c_ty + "Array elems) {\n")
write_c("\t" + struct_name + " *ret = MALLOC(sizeof(" + struct_name + "), \"" + struct_name + "\");\n")
write_c("\tret->datalen = " + consts.get_native_arr_len_call[0] + "elems" + consts.get_native_arr_len_call[1] + ";\n")
write_c("\tif (ret->datalen == 0) {\n")
@SuppressWarnings("unchecked") // We correctly assign various generic arrays
"""
self.c_fn_ty_pfx = "JNIEXPORT "
- self.c_fn_name_pfx = "JNICALL Java_org_ldk_impl_bindings_"
self.c_fn_args_pfx = "JNIEnv *env, jclass clz"
self.file_ext = ".java"
self.ptr_c_ty = "int64_t"
def str_ref_to_c_call(self, var_name, str_len):
return "str_ref_to_java(env, " + var_name + ", " + str_len + ")"
+ def c_fn_name_define_pfx(self, fn_name, has_args):
+ if has_args:
+ return "JNICALL Java_org_ldk_impl_bindings_" + fn_name.replace("_", "_1") + "(JNIEnv *env, jclass clz, "
+ return "JNICALL Java_org_ldk_impl_bindings_" + fn_name.replace("_", "_1") + "(JNIEnv *env, jclass clz"
+
def init_str(self):
res = ""
for ty in self.c_array_class_caches:
out_c = out_c + "\treturn ret;\n"
out_c = out_c + "}\n"
- out_c = out_c + self.c_fn_ty_pfx + "long " + self.c_fn_name_pfx + struct_name.replace("_", "_1") + "_1new (" + self.c_fn_args_pfx + ", jobject o"
+ out_c = out_c + self.c_fn_ty_pfx + "long " + self.c_fn_name_define_pfx(struct_name + "_new", True) + "jobject o"
for var in field_vars:
if isinstance(var, ConvInfo):
out_c = out_c + ", " + var.c_ty + " " + var.arg_name
out_c += (self.c_complex_enum_pfx(struct_name, [x.var_name for x in variant_list], init_meth_jty_strs))
- out_c += (self.c_fn_ty_pfx + self.c_complex_enum_pass_ty(struct_name) + " " + self.c_fn_name_pfx + struct_name.replace("_", "_1") + "_1ref_1from_1ptr (" + self.c_fn_args_pfx + ", " + self.ptr_c_ty + " ptr) {\n")
+ out_c += (self.c_fn_ty_pfx + self.c_complex_enum_pass_ty(struct_name) + " " + self.c_fn_name_define_pfx(struct_name + "_ref_from_ptr", True) + self.ptr_c_ty + " ptr) {\n")
out_c += ("\t" + struct_name + " *obj = (" + struct_name + "*)ptr;\n")
out_c += ("\tswitch(obj->tag) {\n")
for var in variant_list:
if return_type_info.ret_conv is not None:
ret_conv_pfx, ret_conv_sfx = return_type_info.ret_conv
out_java += (" " + method_name + "(")
- out_c += (" " + self.c_fn_name_pfx + method_name.replace('_', '_1') + "(" + self.c_fn_args_pfx)
+ have_args = len(argument_types) > 1 or (len(argument_types) > 0 and argument_types[0].c_ty != "void")
+ out_c += (" " + self.c_fn_name_define_pfx(method_name, have_args))
for idx, arg_conv_info in enumerate(argument_types):
if idx != 0:
out_java += (", ")
- if arg_conv_info.c_ty != "void":
out_c += (", ")
if arg_conv_info.c_ty != "void":
out_c += (arg_conv_info.c_ty + " " + arg_conv_info.arg_name)
"""
self.c_fn_ty_pfx = ""
- self.c_fn_name_pfx = ""
- self.c_fn_args_pfx = "void* ctx_TODO"
self.file_ext = ".ts"
self.ptr_c_ty = "uint32_t"
self.ptr_native_ty = "number"
def str_ref_to_c_call(self, var_name, str_len):
return "str_ref_to_ts(" + var_name + ", " + str_len + ")"
+ def c_fn_name_define_pfx(self, fn_name, have_args):
+ return "TS_" + fn_name + "("
+
def wasm_import_header(self, target):
if target == Target.NODEJS:
return """
out_c = out_c + "\treturn (void*) this_arg;\n"
out_c = out_c + "}\n"
- out_c = out_c + "static inline " + struct_name + " " + struct_name + "_init (" + self.c_fn_args_pfx + ", /*TODO: JS Object Reference */void* o"
+ out_c = out_c + "static inline " + struct_name + " " + struct_name + "_init (/*TODO: JS Object Reference */void* o"
for var in field_var_conversions:
if isinstance(var, ConvInfo):
out_c = out_c + ", " + var.c_ty + " " + var.arg_name
out_c = out_c + "\t\t." + var.var_name + " = " + var.var_name + ",\n"
out_c = out_c + "\t\t.set_" + var.var_name + " = NULL,\n"
else:
- out_c = out_c + "\t\t." + var[1] + " = " + var[0] + "_init(NULL, " + var[1] + "),\n"
+ out_c = out_c + "\t\t." + var[1] + " = " + var[0] + "_init(" + var[1] + "),\n"
out_c = out_c + "\t};\n"
for var in field_var_conversions:
if not isinstance(var, ConvInfo):
out_c = out_c + "\treturn ret;\n"
out_c = out_c + "}\n"
- out_c = out_c + self.c_fn_ty_pfx + "long " + self.c_fn_name_pfx + struct_name.replace("_", "_1") + "_1new (" + self.c_fn_args_pfx + ", /*TODO: JS Object Reference */void* o"
+ out_c = out_c + self.c_fn_ty_pfx + "long TS_" + struct_name + "_new (/*TODO: JS Object Reference */void* o"
for var in field_var_conversions:
if isinstance(var, ConvInfo):
out_c = out_c + ", " + var.c_ty + " " + var.arg_name
out_c = out_c + ", /*TODO: JS Object Reference */ void* " + var[1]
out_c = out_c + ") {\n"
out_c = out_c + "\t" + struct_name + " *res_ptr = MALLOC(sizeof(" + struct_name + "), \"" + struct_name + "\");\n"
- out_c = out_c + "\t*res_ptr = " + struct_name + "_init(NULL, o"
+ out_c = out_c + "\t*res_ptr = " + struct_name + "_init(o"
for var in field_var_conversions:
if isinstance(var, ConvInfo):
out_c = out_c + ", " + var.arg_name
out_java += ("\tstatic { " + struct_name + ".init(); }\n")
out_java += ("\tpublic static native " + struct_name + " " + struct_name + "_ref_from_ptr(long ptr);\n");
- out_c += (self.c_fn_ty_pfx + self.c_complex_enum_pass_ty(struct_name) + " " + self.c_fn_name_pfx + struct_name.replace("_", "_1") + "_1ref_1from_1ptr (" + self.c_fn_args_pfx + ", " + self.ptr_c_ty + " ptr) {\n")
+ out_c += (self.c_fn_ty_pfx + self.c_complex_enum_pass_ty(struct_name) + " TS_" + struct_name + "_ref_from_ptr (" + self.ptr_c_ty + " ptr) {\n")
out_c += ("\t" + struct_name + " *obj = (" + struct_name + "*)ptr;\n")
out_c += ("\tswitch(obj->tag) {\n")
for var in variant_list:
if return_type_info.ret_conv is not None:
ret_conv_pfx, ret_conv_sfx = return_type_info.ret_conv
out_java += (" " + method_name + "(")
- out_c += (" " + self.c_fn_name_pfx + method_name.replace('_', '_1') + "(" + self.c_fn_args_pfx)
+ out_c += (" TS_" + method_name + "(")
method_argument_string = ""
native_call_argument_string = ""
if idx != 0:
method_argument_string += (", ")
native_call_argument_string += ', '
- if arg_conv_info.c_ty != "void":
out_c += (", ")
if arg_conv_info.c_ty != "void":
out_c += (arg_conv_info.c_ty + " " + arg_conv_info.arg_name)