From f724bd1880ba9633e3f2dd530775dc0535d9cc17 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Tue, 21 Sep 2021 03:54:50 +0200 Subject: [Core] Add ClassDB functions to retrieve/construct extensions. Calling the constructor alone is not enough if the class to be instantiated is not a base class. This commit adds two functions, one for retrieving the the extension class reference, the other to construct an instance using the constructor and the extension class reference. --- core/object/class_db.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'core/object/class_db.cpp') diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp index 8e92340c1e..05b3dde4ed 100644 --- a/core/object/class_db.cpp +++ b/core/object/class_db.cpp @@ -545,6 +545,13 @@ Object *ClassDB::instantiate(const StringName &p_class) { return ti->creation_func(); } +Object *ClassDB::construct_extended(Object *(*p_create_func)(), ObjectNativeExtension *p_extension) { + initializing_with_extension = true; + initializing_extension = p_extension; + initializing_extension_instance = p_extension->create_instance(p_extension->class_userdata); + return p_create_func(); +} + bool ClassDB::can_instantiate(const StringName &p_class) { OBJTYPE_RLOCK; -- cgit v1.2.3 From f9ce9a8e103b4b53ad3de032220c3e8799d52409 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Wed, 22 Sep 2021 18:33:29 +0200 Subject: [ClassDB] Unify construct/extension retrieval. --- core/object/class_db.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'core/object/class_db.cpp') diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp index 05b3dde4ed..8ba46e49eb 100644 --- a/core/object/class_db.cpp +++ b/core/object/class_db.cpp @@ -545,10 +545,12 @@ Object *ClassDB::instantiate(const StringName &p_class) { return ti->creation_func(); } -Object *ClassDB::construct_extended(Object *(*p_create_func)(), ObjectNativeExtension *p_extension) { - initializing_with_extension = true; - initializing_extension = p_extension; - initializing_extension_instance = p_extension->create_instance(p_extension->class_userdata); +Object *ClassDB::construct_object(Object *(*p_create_func)(), ObjectNativeExtension *p_extension) { + if (p_extension) { + initializing_with_extension = true; + initializing_extension = p_extension; + initializing_extension_instance = p_extension->create_instance(p_extension->class_userdata); + } return p_create_func(); } -- cgit v1.2.3