Allow to cast custom objects for Variant
#42060
Closed
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.
Allows to cast custom object types to be compatible with
Variant
for binding methods.This PR is created for discussion purposes, feel free to close if you think that the implementation is too complex or wrong, or when a better solution comes in, but if useful, I could continue working on this. 🙂
Usage
Basically the same as for casting enums:
VARIANT_OBJECT_CAST(ListNode);
This is useful for implementing custom object types in C++ modules without having to manually cast
Object
s in code, and allows for such a custom class to appear in the documentation methods API! For concrete use case, see goostengine/goost#12, where this is implemented locally for a single class.Note that casting builtin
Node
works because there's already a support for that inVariant
natively.There are other stuff which can/should be implemented to make this work with C# I think (PtrToArg?), and additionally allow to cast
const *
objects, but this is just to showcase the implementation to @reduz currently.#godotengine-devel IRC discussion: