Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for BitField hint, sync API files. #783

Merged
merged 1 commit into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 38 additions & 9 deletions binding_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,10 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us

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"]});')
if enum_api["is_bitfield"]:
result.append(f'VARIANT_BITFIELD_CAST({class_name}, {class_name}::{enum_api["name"]});')
else:
result.append(f'VARIANT_ENUM_CAST({class_name}, {class_name}::{enum_api["name"]});')
result.append("")

result.append(f"#endif // ! {header_guard}")
Expand Down Expand Up @@ -1194,7 +1197,7 @@ def generate_engine_class_source(class_api, used_classes, fully_used_classes, us
result.append(method_call)

if vararg and ("return_value" in method and method["return_value"]["type"] != "void"):
return_type = method["return_value"]["type"].replace("enum::", "")
return_type = get_enum_fullname(method["return_value"]["type"])
if return_type != "Variant":
result.append(f"\treturn VariantCaster<{return_type}>::cast(ret);")
else:
Expand Down Expand Up @@ -1712,18 +1715,35 @@ def needs_copy_instead_of_move(type_name):


def is_enum(type_name):
return type_name.startswith("enum::")
return type_name.startswith("enum::") or type_name.startswith("bitfield::")


def is_bitfield(type_name):
return type_name.startswith("bitfield::")


def get_enum_class(enum_name: str):
if "." in enum_name:
return enum_name.replace("enum::", "").split(".")[0]
if is_bitfield(enum_name):
return enum_name.replace("bitfield::", "").split(".")[0]
else:
return enum_name.replace("enum::", "").split(".")[0]
else:
return "GlobalConstants"


def get_enum_fullname(enum_name: str):
if is_bitfield(enum_name):
return enum_name.replace("bitfield::", "BitField<") + ">"
else:
return enum_name.replace("enum::", "")


def get_enum_name(enum_name: str):
return enum_name.replace("enum::", "").split(".")[-1]
if is_bitfield(enum_name):
return enum_name.replace("bitfield::", "").split(".")[-1]
else:
return enum_name.replace("enum::", "").split(".")[-1]


def is_variant(type_name):
Expand Down Expand Up @@ -1781,10 +1801,16 @@ def correct_type(type_name, meta=None):
if type_name in type_conversion:
return type_conversion[type_name]
if is_enum(type_name):
base_class = get_enum_class(type_name)
if base_class == "GlobalConstants":
return f"{get_enum_name(type_name)}"
return f"{base_class}::{get_enum_name(type_name)}"
if is_bitfield(type_name):
base_class = get_enum_class(type_name)
if base_class == "GlobalConstants":
return f"BitField<{get_enum_name(type_name)}>"
return f"BitField<{base_class}::{get_enum_name(type_name)}>"
else:
base_class = get_enum_class(type_name)
if base_class == "GlobalConstants":
return f"{get_enum_name(type_name)}"
return f"{base_class}::{get_enum_name(type_name)}"
if is_refcounted(type_name):
return f"Ref<{type_name}>"
if type_name == "Object" or is_engine_class(type_name):
Expand All @@ -1807,6 +1833,9 @@ def get_gdnative_type(type_name):
"float": "double",
}

if type_name.startswith("BitField<"):
return "int64_t"

if type_name in type_conversion_map:
return type_conversion_map[type_name]
return type_name
Expand Down
Loading