Skip to content

Commit 2f66014

Browse files
committed
Allow using unions and structs in the native structure definition.
1 parent 6a87094 commit 2f66014

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

binding_generator.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,15 @@ def generate_engine_classes_bindings(api, output_dir, use_template_get_node):
15241524
expanded_format = native_struct["format"].replace("(", " ").replace(")", ";").replace(",", ";")
15251525
for field in expanded_format.split(";"):
15261526
field_type = field.strip().split(" ")[0].split("::")[0]
1527-
if field_type != "" and not is_included_type(field_type) and not is_pod_type(field_type):
1527+
if (
1528+
field_type != ""
1529+
and field_type != "{"
1530+
and field_type != "}"
1531+
and field_type != "union"
1532+
and field_type != "struct"
1533+
and not is_included_type(field_type)
1534+
and not is_pod_type(field_type)
1535+
):
15281536
if field_type not in used_classes:
15291537
used_classes.append(field_type)
15301538

@@ -1548,9 +1556,18 @@ def generate_engine_classes_bindings(api, output_dir, use_template_get_node):
15481556
result.append("")
15491557

15501558
result.append(f"struct {struct_name} {{")
1559+
indent = 1
15511560
for field in native_struct["format"].split(";"):
15521561
if field != "":
1553-
result.append(f"\t{field};")
1562+
if "}" in field:
1563+
indent -= 1
1564+
if "{" in field:
1565+
parts = field.split("{")
1566+
result.append(f"{'\t' * indent}{parts[0]}{{")
1567+
indent += 1
1568+
result.append(f"{'\t' * indent}{parts[1]};")
1569+
else:
1570+
result.append(f"{'\t' * indent}{field};")
15541571
result.append("};")
15551572

15561573
result.append("")

0 commit comments

Comments
 (0)