Improve user-friendliness of "return value as function param" pattern in GDExtension API

This commit introduce separate types (e.g. GDNativeStringPtr vs GDNativeUninitializedStringPtr)
depending on if the pointed data is already initialized (C++ style where constructor is alway
called when create a variable even if it is to be passed as return value) or not (C style).
On top of that, small changes has been made to `GDNativeInterface` so that it methods are
consistent on using uninitialized return value.
This commit is contained in:
Emmanuel Leblond 2023-05-13 19:05:54 +02:00
parent 5c653c27cd
commit e785dd9dd9
No known key found for this signature in database
GPG key ID: C360860E645EFFC0
4 changed files with 116 additions and 103 deletions

View file

@ -425,10 +425,10 @@ void GDExtension::_unregister_extension_class(GDExtensionClassLibraryPtr p_libra
self->extension_classes.erase(class_name);
}
void GDExtension::_get_library_path(GDExtensionClassLibraryPtr p_library, GDExtensionStringPtr r_path) {
void GDExtension::_get_library_path(GDExtensionClassLibraryPtr p_library, GDExtensionUninitializedStringPtr r_path) {
GDExtension *self = reinterpret_cast<GDExtension *>(p_library);
*(String *)r_path = self->library_path;
memnew_placement(r_path, String(self->library_path));
}
Error GDExtension::open_library(const String &p_path, const String &p_entry_symbol) {