You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-09 12:50:35 +00:00
[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.
This commit is contained in:
@@ -862,6 +862,18 @@ static GDNativeClassConstructor gdnative_classdb_get_constructor(const char *p_c
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static GDNativeExtensionPtr gdnative_classdb_get_extension(const char *p_classname) {
|
||||
ClassDB::ClassInfo *class_info = ClassDB::classes.getptr(StringName(p_classname));
|
||||
if (class_info) {
|
||||
return (GDNativeExtensionPtr)class_info->native_extension;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static GDNativeObjectPtr gdnative_classdb_construct_extended(GDNativeClassConstructor p_constructor, GDNativeExtensionPtr p_extension) {
|
||||
return (GDNativeObjectPtr)ClassDB::construct_extended((Object * (*)()) p_constructor, (ObjectNativeExtension *)p_extension);
|
||||
}
|
||||
|
||||
static void *gdnative_classdb_get_class_tag(const char *p_classname) {
|
||||
ClassDB::ClassInfo *class_info = ClassDB::classes.getptr(p_classname);
|
||||
return class_info ? class_info->class_ptr : nullptr;
|
||||
@@ -1010,6 +1022,8 @@ void gdnative_setup_interface(GDNativeInterface *p_interface) {
|
||||
/* CLASSDB */
|
||||
|
||||
gdni.classdb_get_constructor = gdnative_classdb_get_constructor;
|
||||
gdni.classdb_get_extension = gdnative_classdb_get_extension;
|
||||
gdni.classdb_construct_extended = gdnative_classdb_construct_extended;
|
||||
gdni.classdb_get_method_bind = gdnative_classdb_get_method_bind;
|
||||
gdni.classdb_get_class_tag = gdnative_classdb_get_class_tag;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user