1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-06 12:20:30 +00:00

Improve logic around using Ref<T> with GDExtension virtual functions

This commit is contained in:
Bastiaan Olij
2022-12-11 21:31:01 +11:00
parent ba4bd7f009
commit 7502e1dc0d
3 changed files with 32 additions and 0 deletions

View File

@@ -879,6 +879,23 @@ static GDObjectInstanceID gdextension_object_get_instance_id(GDExtensionConstObj
return (GDObjectInstanceID)o->get_instance_id();
}
static GDExtensionObjectPtr gdextension_ref_get_object(GDExtensionConstRefPtr p_ref) {
const Ref<RefCounted> *ref = (const Ref<RefCounted> *)p_ref;
if (ref == nullptr || ref->is_null()) {
return (GDExtensionObjectPtr) nullptr;
} else {
return (GDExtensionObjectPtr)ref->ptr();
}
}
static void gdextension_ref_set_object(GDExtensionRefPtr p_ref, GDExtensionObjectPtr p_object) {
Ref<RefCounted> *ref = (Ref<RefCounted> *)p_ref;
ERR_FAIL_NULL(ref);
Object *o = (RefCounted *)p_object;
ref->reference_ptr(o);
}
static GDExtensionScriptInstancePtr gdextension_script_instance_create(const GDExtensionScriptInstanceInfo *p_info, GDExtensionScriptInstanceDataPtr p_instance_data) {
ScriptInstanceExtension *script_instance_extension = memnew(ScriptInstanceExtension);
script_instance_extension->instance = p_instance_data;
@@ -1057,6 +1074,11 @@ void gdextension_setup_interface(GDExtensionInterface *p_interface) {
gde_interface.object_get_instance_from_id = gdextension_object_get_instance_from_id;
gde_interface.object_get_instance_id = gdextension_object_get_instance_id;
/* REFERENCE */
gde_interface.ref_get_object = gdextension_ref_get_object;
gde_interface.ref_set_object = gdextension_ref_set_object;
/* SCRIPT INSTANCE */
gde_interface.script_instance_create = gdextension_script_instance_create;