Skip to content

Commit 4dd6e8e

Browse files
committed
GDExtension: Implement GDExtensionLoader concept
- Implements the concept of GDExtension loaders that can be used to customize how GDExtensions are loaded and initialized. - Moves the parsing of `.gdextension` config files to the new `GDExtensionLibraryLoader`. - `GDExtensionManager` is now meant to be the main way to load/unload extensions and can optionally take a `GDExtensionLoader`. - `EditorFileSystem` avoids unloading extensions if the file still exists, this should prevent unloading extensions that are outside the user project.
1 parent 1bd740d commit 4dd6e8e

File tree

9 files changed

+584
-347
lines changed

9 files changed

+584
-347
lines changed

core/extension/gdextension.cpp

Lines changed: 32 additions & 325 deletions
Large diffs are not rendered by default.

core/extension/gdextension.h

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@
3131
#ifndef GDEXTENSION_H
3232
#define GDEXTENSION_H
3333

34-
#include <functional>
35-
3634
#include "core/extension/gdextension_interface.h"
35+
#include "core/extension/gdextension_loader.h"
3736
#include "core/io/config_file.h"
3837
#include "core/io/resource_loader.h"
3938
#include "core/object/ref_counted.h"
40-
#include "core/os/shared_object.h"
4139

4240
class GDExtensionMethodBind;
4341

@@ -46,8 +44,8 @@ class GDExtension : public Resource {
4644

4745
friend class GDExtensionManager;
4846

49-
void *library = nullptr; // pointer if valid,
50-
String library_path;
47+
Ref<GDExtensionLoader> loader;
48+
5149
bool reloadable = false;
5250

5351
struct Extension {
@@ -96,8 +94,6 @@ class GDExtension : public Resource {
9694
int32_t level_initialized = -1;
9795

9896
#ifdef TOOLS_ENABLED
99-
uint64_t resource_last_modified_time = 0;
100-
uint64_t library_last_modified_time = 0;
10197
bool is_reloading = false;
10298
Vector<GDExtensionMethodBind *> invalid_methods;
10399
Vector<ObjectID> instance_bindings;
@@ -124,11 +120,12 @@ class GDExtension : public Resource {
124120
virtual bool editor_can_reload_from_file() override { return false; } // Reloading is handled in a special way.
125121

126122
static String get_extension_list_config_file();
127-
static String find_extension_library(const String &p_path, Ref<ConfigFile> p_config, std::function<bool(String)> p_has_feature, PackedStringArray *r_tags = nullptr);
128-
static Vector<SharedObject> find_extension_dependencies(const String &p_path, Ref<ConfigFile> p_config, std::function<bool(String)> p_has_feature);
129123

130-
Error open_library(const String &p_path, const String &p_entry_symbol, Vector<SharedObject> *p_dependencies = nullptr);
124+
const Ref<GDExtensionLoader> get_loader() const { return loader; }
125+
126+
Error open_library(const String &p_path, const Ref<GDExtensionLoader> &p_loader);
131127
void close_library();
128+
bool is_library_open() const;
132129

133130
enum InitializationLevel {
134131
INITIALIZATION_LEVEL_CORE = GDEXTENSION_INITIALIZATION_CORE,
@@ -146,17 +143,11 @@ class GDExtension : public Resource {
146143
#endif
147144

148145
public:
149-
bool is_library_open() const;
150-
151146
#ifdef TOOLS_ENABLED
152147
bool is_reloadable() const { return reloadable; }
153148
void set_reloadable(bool p_reloadable) { reloadable = p_reloadable; }
154149

155150
bool has_library_changed() const;
156-
void update_last_modified_time(uint64_t p_resource_last_modified_time, uint64_t p_library_last_modified_time) {
157-
resource_last_modified_time = p_resource_last_modified_time;
158-
library_last_modified_time = p_library_last_modified_time;
159-
}
160151

161152
void track_instance_binding(Object *p_object);
162153
void untrack_instance_binding(Object *p_object);

0 commit comments

Comments
 (0)