Skip to content

Commit 9fd0a12

Browse files
committed
Correct element type for TypedArray<>
1 parent 11773e5 commit 9fd0a12

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

binding_generator.py

+16-13
Original file line numberDiff line numberDiff line change
@@ -1918,11 +1918,17 @@ def generate_engine_class_source(class_api, used_classes, fully_used_classes, us
19181918
)
19191919
method_call = "\t"
19201920
has_return = "return_value" in method and method["return_value"]["type"] != "void"
1921+
has_meta = "return_value" in method and "meta" in method["return_value"]
19211922

19221923
if has_return:
1923-
result.append(
1924-
f'\tCHECK_METHOD_BIND_RET(_gde_method_bind, {get_default_value_for_type(method["return_value"]["type"])});'
1925-
)
1924+
if has_meta:
1925+
result.append(
1926+
f'\tCHECK_METHOD_BIND_RET(_gde_method_bind, {get_default_value_for_type(method["return_value"]["type"], method["return_value"]["meta"])});'
1927+
)
1928+
else:
1929+
result.append(
1930+
f'\tCHECK_METHOD_BIND_RET(_gde_method_bind, {get_default_value_for_type(method["return_value"]["type"])});'
1931+
)
19261932
else:
19271933
result.append("\tCHECK_METHOD_BIND(_gde_method_bind);")
19281934

@@ -2708,15 +2714,9 @@ def correct_default_value(value, type_name):
27082714
return value
27092715

27102716

2711-
def correct_typed_array(type_name):
2712-
if type_name.startswith("typedarray::"):
2713-
return type_name.replace("typedarray::", "TypedArray<") + ">"
2714-
return type_name
2715-
2716-
27172717
def correct_type(type_name, meta=None, use_alias=True):
27182718
type_conversion = {"float": "double", "int": "int64_t", "Nil": "Variant"}
2719-
if meta is not None:
2719+
if meta is not None and not type_name.startswith("typedarray::"):
27202720
if "int" in meta:
27212721
return f"{meta}_t"
27222722
elif meta in type_conversion:
@@ -2726,7 +2726,10 @@ def correct_type(type_name, meta=None, use_alias=True):
27262726
if type_name in type_conversion:
27272727
return type_conversion[type_name]
27282728
if type_name.startswith("typedarray::"):
2729-
return type_name.replace("typedarray::", "TypedArray<") + ">"
2729+
elem_type = type_name[len("typedarray::") :]
2730+
if meta is not None:
2731+
elem_type = correct_type(elem_type, meta)
2732+
return "TypedArray<" + elem_type + ">"
27302733
if is_enum(type_name):
27312734
if is_bitfield(type_name):
27322735
base_class = get_enum_class(type_name)
@@ -2832,15 +2835,15 @@ def get_operator_id_name(op):
28322835
return op_id_map[op]
28332836

28342837

2835-
def get_default_value_for_type(type_name):
2838+
def get_default_value_for_type(type_name, meta=None):
28362839
if type_name == "int":
28372840
return "0"
28382841
if type_name == "float":
28392842
return "0.0"
28402843
if type_name == "bool":
28412844
return "false"
28422845
if type_name.startswith("typedarray::"):
2843-
return f"{correct_type(type_name)}()"
2846+
return f"{correct_type(type_name, meta)}()"
28442847
if is_enum(type_name):
28452848
return f"{correct_type(type_name)}(0)"
28462849
if is_variant(type_name):

0 commit comments

Comments
 (0)