Merge pull request #699 from bruvzg/enum_and_ptr_binds

pull/706/head
Rémi Verschelde 2022-02-16 12:32:26 +01:00 committed by GitHub
commit d9111350b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 45 additions and 0 deletions

View File

@ -62,6 +62,7 @@ def generate_bindings(api_filepath, use_template_get_node, output_dir="."):
target_dir.mkdir(parents=True) target_dir.mkdir(parents=True)
generate_global_constants(api, target_dir) generate_global_constants(api, target_dir)
generate_global_constant_binds(api, target_dir)
generate_builtin_bindings(api, target_dir, "float_64") generate_builtin_bindings(api, target_dir, "float_64")
generate_engine_classes_bindings(api, target_dir, use_template_get_node) generate_engine_classes_bindings(api, target_dir, use_template_get_node)
generate_utility_functions(api, target_dir) generate_utility_functions(api, target_dir)
@ -868,6 +869,8 @@ def generate_engine_classes_bindings(api, output_dir, use_template_get_node):
result.append(f"\t{field};") result.append(f"\t{field};")
result.append("};") result.append("};")
result.append("")
result.append(f"GDVIRTUAL_NATIVE_PTR({struct_name});")
result.append("") result.append("")
result.append("} // namespace godot") result.append("} // namespace godot")
result.append("") result.append("")
@ -1005,6 +1008,12 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us
result.append("") result.append("")
result.append("} // namespace godot") result.append("} // namespace godot")
result.append("")
if "enums" in class_api and class_name != "Object":
for enum_api in class_api["enums"]:
result.append(f'VARIANT_ENUM_CAST({class_name}, {class_name}::{enum_api["name"]});')
result.append("")
result.append(f"#endif // ! {header_guard}") result.append(f"#endif // ! {header_guard}")
@ -1188,6 +1197,42 @@ def generate_global_constants(api, output_dir):
header_file.write("\n".join(header)) header_file.write("\n".join(header))
def generate_global_constant_binds(api, output_dir):
include_gen_folder = Path(output_dir) / "include" / "godot_cpp" / "classes"
source_gen_folder = Path(output_dir) / "src" / "classes"
include_gen_folder.mkdir(parents=True, exist_ok=True)
source_gen_folder.mkdir(parents=True, exist_ok=True)
# Generate header
header = []
add_header("global_constants_binds.hpp", header)
header_filename = include_gen_folder / "global_constants_binds.hpp"
header_guard = "GODOT_CPP_GLOBAL_CONSTANTS_BINDS_HPP"
header.append(f"#ifndef {header_guard}")
header.append(f"#define {header_guard}")
header.append("")
header.append("#include <godot_cpp/classes/global_constants.hpp>")
header.append("#include <godot_cpp/core/binder_common.hpp>")
header.append("")
for enum_def in api["global_enums"]:
if enum_def["name"].startswith("Variant."):
continue
header.append(f'VARIANT_ENUM_CAST(, godot::{enum_def["name"]});')
header.append("")
header.append(f"#endif // ! {header_guard}")
with header_filename.open("w+") as header_file:
header_file.write("\n".join(header))
def generate_utility_functions(api, output_dir): def generate_utility_functions(api, output_dir):
include_gen_folder = Path(output_dir) / "include" / "godot_cpp" / "variant" include_gen_folder = Path(output_dir) / "include" / "godot_cpp" / "variant"
source_gen_folder = Path(output_dir) / "src" / "variant" source_gen_folder = Path(output_dir) / "src" / "variant"