From 431e30bc3273c83315725f56365845f0b89c0524 Mon Sep 17 00:00:00 2001 From: David Snopek Date: Fri, 17 Feb 2023 10:49:09 -0600 Subject: Ensure GDExtension class is the correct type for the Godot engine class --- src/core/object.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/core/object.cpp') 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 +#include + 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(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(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(gdextension_interface_object_get_instance_binding(p_engine_object, token, binding_callbacks)); +} + +} // namespace internal + MethodInfo::MethodInfo() : flags(GDEXTENSION_METHOD_FLAG_NORMAL) {} -- cgit v1.2.3