diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2023-06-15 10:50:27 +0200 |
|---|---|---|
| committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-06-15 10:50:27 +0200 |
| commit | 8c5c29f2a3d519693f153118e6495dab7335a350 (patch) | |
| tree | 894c8d69149cb75a9cc2edf216cb6363aadd9bff /core/object | |
| parent | 2c22e56e37e26ec82d771209c23f2adeb9873335 (diff) | |
| parent | 36f4b99638af24fc9d64563f4111ec8c13243cae (diff) | |
| download | redot-engine-8c5c29f2a3d519693f153118e6495dab7335a350.tar.gz | |
Merge pull request #78061 from dsnopek/gdextension-class-not-exposed
Fix wrapping Object's in GDExtension that aren't exposed
Diffstat (limited to 'core/object')
| -rw-r--r-- | core/object/object.cpp | 24 | ||||
| -rw-r--r-- | core/object/object.h | 12 |
2 files changed, 25 insertions, 11 deletions
diff --git a/core/object/object.cpp b/core/object/object.cpp index d6937539c7..c76188a2cd 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -1719,6 +1719,30 @@ uint32_t Object::get_edited_version() const { } #endif +StringName Object::get_class_name_for_extension(const GDExtension *p_library) const { + // Only return the class name per the extension if it matches the given p_library. + if (_extension && _extension->library == p_library) { + return _extension->class_name; + } + + // Extensions only have wrapper classes for classes exposed in ClassDB. + const StringName *class_name = _get_class_namev(); + if (ClassDB::is_class_exposed(*class_name)) { + return *class_name; + } + + // Find the nearest parent class that's exposed. + StringName parent_class = ClassDB::get_parent_class(*class_name); + while (parent_class != StringName()) { + if (ClassDB::is_class_exposed(parent_class)) { + return parent_class; + } + parent_class = ClassDB::get_parent_class(parent_class); + } + + return SNAME("Object"); +} + void Object::set_instance_binding(void *p_token, void *p_binding, const GDExtensionInstanceBindingCallbacks *p_callbacks) { // This is only meant to be used on creation by the binder. ERR_FAIL_COND(_instance_bindings != nullptr); diff --git a/core/object/object.h b/core/object/object.h index 6f626b0ed0..a3e9d025ea 100644 --- a/core/object/object.h +++ b/core/object/object.h @@ -800,17 +800,7 @@ public: return *_class_name_ptr; } - _FORCE_INLINE_ const StringName &get_class_name_for_extension(const GDExtension *p_library) const { - // Only return the class name per the extension if it matches the given p_library. - if (_extension && _extension->library == p_library) { - return _extension->class_name; - } - // Otherwise, return the name of the built-in class. - if (unlikely(!_class_name_ptr)) { - return *_get_class_namev(); - } - return *_class_name_ptr; - } + StringName get_class_name_for_extension(const GDExtension *p_library) const; /* IAPI */ |
