summaryrefslogtreecommitdiff
path: root/python/generator.cpp
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2025-12-08 16:33:51 -0500
committerGlenn Smith <glenn@vector35.com>2025-12-09 17:10:39 -0500
commit6728415172553838701009676202433153533565 (patch)
tree84eeb1528c2de4659762255307ff37bc8bce548a /python/generator.cpp
parente4dc9f370f948bf8071e38667fc9606f13ea0f70 (diff)
Python: Fix enums not being casted to their types in generator
Diffstat (limited to 'python/generator.cpp')
-rw-r--r--python/generator.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/python/generator.cpp b/python/generator.cpp
index 41fbb159..6dd983b4 100644
--- a/python/generator.cpp
+++ b/python/generator.cpp
@@ -470,6 +470,9 @@ int main(int argc, char* argv[])
&& (i.second->GetChildType()->GetChildType()->IsSigned());
// Pointer returns will be automatically wrapped to return None on null pointer
bool pointerResult = (i.second->GetChildType()->GetClass() == PointerTypeClass);
+ // Enum returns will automatically cast to the enum type
+ bool enumResult = (i.second->GetChildType()->GetClass() == NamedTypeReferenceClass
+ && i.second->GetChildType()->GetNamedTypeReference()->GetTypeReferenceClass() == EnumNamedTypeClass);
// From python -> C python3 requires str -> str.encode('charmap')
bool swizzleArgs = true;
@@ -617,6 +620,13 @@ int main(int argc, char* argv[])
fprintf(out, "\t\treturn None\n");
fprintf(out, "\treturn result\n");
}
+ else if (enumResult)
+ {
+ // Emit wrapper to cast result to enum type
+ fprintf(out, "\treturn ");
+ OutputSwizzledType(out, i.second->GetChildType().GetValue());
+ fprintf(out, "(%s)", stringArgFuncCall.c_str());
+ }
else
{
fprintf(out, "\treturn ");