Skip to content

Commit 6728415

Browse files
committed
Python: Fix enums not being casted to their types in generator
1 parent e4dc9f3 commit 6728415

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

python/generator.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,9 @@ int main(int argc, char* argv[])
470470
&& (i.second->GetChildType()->GetChildType()->IsSigned());
471471
// Pointer returns will be automatically wrapped to return None on null pointer
472472
bool pointerResult = (i.second->GetChildType()->GetClass() == PointerTypeClass);
473+
// Enum returns will automatically cast to the enum type
474+
bool enumResult = (i.second->GetChildType()->GetClass() == NamedTypeReferenceClass
475+
&& i.second->GetChildType()->GetNamedTypeReference()->GetTypeReferenceClass() == EnumNamedTypeClass);
473476

474477
// From python -> C python3 requires str -> str.encode('charmap')
475478
bool swizzleArgs = true;
@@ -617,6 +620,13 @@ int main(int argc, char* argv[])
617620
fprintf(out, "\t\treturn None\n");
618621
fprintf(out, "\treturn result\n");
619622
}
623+
else if (enumResult)
624+
{
625+
// Emit wrapper to cast result to enum type
626+
fprintf(out, "\treturn ");
627+
OutputSwizzledType(out, i.second->GetChildType().GetValue());
628+
fprintf(out, "(%s)", stringArgFuncCall.c_str());
629+
}
620630
else
621631
{
622632
fprintf(out, "\treturn ");

0 commit comments

Comments
 (0)