diff options
Diffstat (limited to 'src/core/object.cpp')
-rw-r--r-- | src/core/object.cpp | 30 |
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) {} |