Implement copy and move constructors for gdxx::GodotCustomClass #2
Labels
No labels
blocked
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
queertherians.org/gdxx#2
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Starting at line 138 in
include/GodotClass.hpp:Copying will likely involve some sort of call to
gdxx::API::variant_new_copy(...)if that is compatible with our instantiated object, while updating(!) the binding1 to the native object itself. Moving might also require updating the binding1.More research or discussion is required before I'll feel confident enough to tackle this one.
"binding", or whatever associates the Godot Object to the Native Object; I'm currently unsure on the nomenclature ↩︎
Clarification received from #1 (comment link): The native object is more of a "wrapper" around the Godot object instance, and in the case of a custom class, also happens to contain the methods that are to be registered within
gdxx::GodotCustomClass<...>::Register()via #5.There shall exist one instance of the native class per instance of a CustomClass (or wrapped ExternClass) instance.
Fetching of the native object reference within Godot (or even blindly from native via a Godot Object pointer) is managed via
API::object_get_instance_binding(...). Lifetime is managed via the InstanceBindingCallbacks (wrapped extern) or ClassCreationInfo (native-defined) callbacks.As such, due to these insights gained from #1, moving or copying does not actually make any sense for native objects! This issue is to be closed as not planned once the
#warningis removed; the copy and move constructors are to remain deleted.As an additional note, object copying is theoretically possible, but it should be kept in mind that doing
API::variant_new_copyseems to just copy it as a reference. A true copy would involve the construction of a new object and doing a deep-copy of all elements (through a copy constructor for native objects, and/or some kind ofclone(),copy(), orduplicate()method for Godot objects, in e.g. gdscript).This type of copying, specifically the method name to be defined for cloning or copying in the Godot/gdscript side, seems to be undefined by the Godot spec, and as such, a copy constructor and cloning methodology is left as an exercise to the user of the library. Copy functionality will be left out of the base library. Move functionality still doesn't make much sense, as the lifetime of the object is tied to the Godot object's lifetime, and they are always passed by reference, and never by copy/move. Still closing.