X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=genbindings.py;h=c9ae45ca252575c7cf0a42e7774584a0d907c098;hb=fa130da4108815a8b17c3c093a91fc3d83754a0f;hp=fb3ad6819a16e7cace4b7ce0cb3c9708c8181179;hpb=ffa3026fb30d06e6abd1b5ee757a239a04e20b80;p=ldk-java diff --git a/genbindings.py b/genbindings.py index fb3ad681..c9ae45ca 100755 --- a/genbindings.py +++ b/genbindings.py @@ -26,8 +26,12 @@ elif sys.argv[6] == "typescript": target = typescript_strings.Target.NODEJS if len(sys.argv) == 8 and sys.argv[7] == 'browser': target = typescript_strings.Target.BROWSER +elif sys.argv[6] == "c_sharp": + import csharp_strings + from csharp_strings import Consts + target = csharp_strings.Target.CSHARP else: - print("Only java or typescript can be set for lang") + print("Only java, typescript, or c_sharp can be set for lang") sys.exit(1) @@ -214,6 +218,11 @@ def java_c_types(fn_arg, ret_arr_len): rust_obj = "LDKTransaction" assert var_is_arr_regex.match(fn_arg[8:]) arr_access = "data" + elif fn_arg.startswith("LDKWitness ") or fn_arg == "LDKWitness": + fn_arg = "uint8_t (*" + fn_arg[11:] + ")[datalen]" + rust_obj = "LDKWitness" + assert var_is_arr_regex.match(fn_arg[8:]) + arr_access = "data" elif fn_arg.startswith("LDKCVec_"): is_ptr = False if "*" in fn_arg: @@ -259,7 +268,7 @@ def java_c_types(fn_arg, ret_arr_len): fn_arg = fn_arg[4:].strip() is_primitive = True elif fn_arg.startswith("bool"): - java_ty = "boolean" + java_ty = consts.c_type_map['bool'][0] c_ty = "jboolean" fn_ty_arg = "Z" arr_ty = "bool" @@ -273,11 +282,11 @@ def java_c_types(fn_arg, ret_arr_len): arr_ty = "uint8_t" fn_arg = fn_arg[7:].strip() is_primitive = True - elif fn_arg.startswith("LDKu5") or fn_arg.startswith("LDKWitnessVersion"): + elif fn_arg.startswith("LDKU5") or fn_arg.startswith("LDKWitnessVersion"): java_ty = consts.c_type_map['uint8_t'][0] - if fn_arg.startswith("LDKu5"): + if fn_arg.startswith("LDKU5"): java_hu_ty = "UInt5" - rust_obj = "LDKu5" + rust_obj = "LDKU5" fn_arg = fn_arg[6:].strip() else: java_hu_ty = "WitnessVersion" @@ -1054,6 +1063,7 @@ with open(sys.argv[1]) as in_h, open(f"{sys.argv[2]}/bindings{consts.file_ext}", with open(f"{sys.argv[3]}/structs/TxOut{consts.file_ext}", "w") as out_java_struct: out_java_struct.write(consts.hu_struct_file_prefix) out_java_struct.write(consts.txout_defn) + out_java_struct.write(consts.hu_struct_file_suffix) fn_line = "struct LDKCVec_u8Z TxOut_get_script_pubkey (struct LDKTxOut* thing)" write_c(fn_line + " {") write_c("\treturn CVec_u8Z_clone(&thing->script_pubkey);") @@ -1068,6 +1078,7 @@ with open(sys.argv[1]) as in_h, open(f"{sys.argv[2]}/bindings{consts.file_ext}", with open(f"{sys.argv[3]}/structs/BigEndianScalar{consts.file_ext}", "w") as out_java_struct: out_java_struct.write(consts.hu_struct_file_prefix) out_java_struct.write(consts.scalar_defn) + out_java_struct.write(consts.hu_struct_file_suffix) fn_line = "struct LDKThirtyTwoBytes BigEndianScalar_get_bytes (struct LDKBigEndianScalar* thing)" write_c(fn_line + " {\n") write_c("\tLDKThirtyTwoBytes ret = { .data = *thing->big_endian_bytes };\n") @@ -1118,23 +1129,23 @@ with open(sys.argv[1]) as in_h, open(f"{sys.argv[2]}/bindings{consts.file_ext}", else: assert(line == "\n") - out_java.write(consts.bindings_footer) + out_java.write(consts.bindings_footer()) for struct_name in opaque_structs: with open(f"{sys.argv[3]}/structs/{struct_name.replace('LDK', '')}{consts.file_ext}", "a") as out_java_struct: - out_java_struct.write("}\n") + out_java_struct.write("}\n" + consts.hu_struct_file_suffix) for struct_name in trait_structs: with open(f"{sys.argv[3]}/structs/{struct_name.replace('LDK', '')}{consts.file_ext}", "a") as out_java_struct: - out_java_struct.write("}\n") + out_java_struct.write("}\n" + consts.hu_struct_file_suffix) for struct_name in complex_enums: with open(f"{sys.argv[3]}/structs/{struct_name.replace('LDK', '').replace('COption', 'Option')}{consts.file_ext}", "a") as out_java_struct: - out_java_struct.write("}\n") + out_java_struct.write("}\n" + consts.hu_struct_file_suffix) for struct_name in result_types: with open(f"{sys.argv[3]}/structs/{struct_name.replace('LDKCResult', 'Result')}{consts.file_ext}", "a") as out_java_struct: - out_java_struct.write("}\n") + out_java_struct.write("}\n" + consts.hu_struct_file_suffix) for struct_name in tuple_types: struct_hu_name = struct_name.replace("LDKC2Tuple", "TwoTuple").replace("LDKC3Tuple", "ThreeTuple") with open(f"{sys.argv[3]}/structs/{struct_hu_name}{consts.file_ext}", "a") as out_java_struct: - out_java_struct.write("}\n") + out_java_struct.write("}\n" + consts.hu_struct_file_suffix) with open(f"{sys.argv[4]}/bindings.c.body", "w") as out_c: out_c.write(consts.c_file_pfx)