summaryrefslogtreecommitdiffstats
path: root/src/core/object.cpp
diff options
context:
space:
mode:
authorDavid Snopek <dsnopek@gmail.com>2023-05-24 21:17:12 -0500
committerGitHub <noreply@github.com>2023-05-24 21:17:12 -0500
commit8052f818b47c163d3e0a19b13282d909ebfa55f2 (patch)
tree52ec76b9da866251232b46599710a64d54a81dd9 /src/core/object.cpp
parent08bc2ef680cd8b536519d7f59c6f760e96a3d0a8 (diff)
parent431e30bc3273c83315725f56365845f0b89c0524 (diff)
downloadredot-cpp-8052f818b47c163d3e0a19b13282d909ebfa55f2.tar.gz
Merge pull request #1050 from dsnopek/object-correct-class
Ensure GDExtension class is the correct type for the Godot engine class
Diffstat (limited to 'src/core/object.cpp')
-rw-r--r--src/core/object.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/core/object.cpp b/src/core/object.cpp
index a29fd39..54cc013 100644
--- a/src/core/object.cpp
+++ b/src/core/object.cpp
@@ -30,8 +30,38 @@
#include <godot_cpp/core/object.hpp>
+#include <godot_cpp/core/class_db.hpp>
+
namespace godot {
+namespace internal {
+
+Object *get_object_instance_binding(GodotObject *p_engine_object) {
+ if (p_engine_object == nullptr) {
+ return nullptr;
+ }
+
+ // Get existing instance binding, if one already exists.
+ GDExtensionObjectPtr instance = gdextension_interface_object_get_instance_binding(p_engine_object, token, nullptr);
+ if (instance != nullptr) {
+ return reinterpret_cast<Object *>(instance);
+ }
+
+ // Otherwise, try to look up the correct binding callbacks.
+ const GDExtensionInstanceBindingCallbacks *binding_callbacks = nullptr;
+ StringName class_name;
+ if (gdextension_interface_object_get_class_name(p_engine_object, library, reinterpret_cast<GDExtensionStringNamePtr>(class_name._native_ptr()))) {
+ binding_callbacks = ClassDB::get_instance_binding_callbacks(class_name);
+ }
+ if (binding_callbacks == nullptr) {
+ binding_callbacks = &Object::___binding_callbacks;
+ }
+
+ return reinterpret_cast<Object *>(gdextension_interface_object_get_instance_binding(p_engine_object, token, binding_callbacks));
+}
+
+} // namespace internal
+
MethodInfo::MethodInfo() :
flags(GDEXTENSION_METHOD_FLAG_NORMAL) {}