diff options
| author | Glenn Smith <glenn@vector35.com> | 2025-12-08 16:33:51 -0500 |
|---|---|---|
| committer | Glenn Smith <glenn@vector35.com> | 2025-12-09 17:10:39 -0500 |
| commit | 6728415172553838701009676202433153533565 (patch) | |
| tree | 84eeb1528c2de4659762255307ff37bc8bce548a /python | |
| parent | e4dc9f370f948bf8071e38667fc9606f13ea0f70 (diff) | |
Python: Fix enums not being casted to their types in generator
Diffstat (limited to 'python')
| -rw-r--r-- | python/generator.cpp | 10 |
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 "); |
