Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrapping Object's in GDExtension that aren't exposed #78061

Merged
merged 1 commit into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions core/object/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 1 addition & 11 deletions core/object/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -800,17 +800,7 @@ class Object {
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 */

Expand Down