GH-835 Fix enum registration #847
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #835
Abstract
This bug is twofold:
id
property on the kotlin side) were wrongly interpreted as we always used the kotlin ordinal for all manipulationsPossible solution
This PR fixes both of these issues and provide convenience functions for handling enum ordinals like
godotOrdinal
as an extension property onEnum<*>
which is also used internally.A new interface
GodotEnum
is introduced to be able to implement these ordinal shenanigans (basically just a common interface for generated godot enum to define a common api for the commonid
property we generated anyways for all of them).A new Variant caster for enum types is introduced, which resolved these issues and makes the cutom enum registration obsolete (still required for enum flags and enum lists for now though).
@CedNaru Not sure if the VariantCaster is really the right tool for the job but sure is convenient here :-)
Needed discussion points2 Things i don't like in my approach currently and until these are discussed, the PR stays in Draft mode:The new variant caster is a class rather than an object. Meaning we allocate as many instances of it as there are enum registrations. Sometimes even multipleWe do a type check on each call to/from kotlin to/from godot for all enum registrations in order to get the "proper" godot ordinal of the enumI personally can live with both of them, but they are not ideal. Maybe you have some ideas here.sample of generated code:
before:
after: