Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add variant_internal.hpp. #1655

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Ivorforce
Copy link
Contributor

@Ivorforce Ivorforce commented Nov 26, 2024

This module contains VariantInternalType, VariantInternal, VariantGetInternalPtr, VariantInternalAccessor and VariantDefaultInitializer, facilitating access and manipulation of a Variant's internal value in various ways.

The reference godot variant_internal.hpp is here. I chose a different, less boilerplate-y approach to implementation. It should work the same though. Doing it this way should decrease maintenance (and implementation) effort, since most of these are just copy-pasted code without any type specific logic (with the exception of Object *).

There are a few small differences:

  • VariantInternalType does not exist in godot's implementation. I added it because it makes implementation of the other functions easier.
  • get_object returns Object * const * in my implementation, but const Object ** in godot's. Technically speaking, godot's implementation is wrong, because it allows manipulation of the contained Object *, even though a const Variant was supplied. Godot uses a C-style cast that acts as a const_cast to avoid cast issues.
  • VariantInternalAccessor is not implemented for Object *, even though it is in Godot. I believe it is not possible to replicate the intended behavior without access to Variant::object_assign (or internal ObjData). I made it fail statically using SFINAE.

I think the rest should be the same.

PR contains a unit test for one of the internal accessors.

Depends on #1654.

This module contains VariantInternalType, VariantInternal, VariantGetInternalPtr, VariantInternalAccessor and VariantDefaultInitializer, allowing to access and manipulate Variant's internal values.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant