diff options
Diffstat (limited to 'modules/mono/glue/base_object_glue.cpp')
-rw-r--r-- | modules/mono/glue/base_object_glue.cpp | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/modules/mono/glue/base_object_glue.cpp b/modules/mono/glue/base_object_glue.cpp index 8c77220b85..f370883320 100644 --- a/modules/mono/glue/base_object_glue.cpp +++ b/modules/mono/glue/base_object_glue.cpp @@ -51,7 +51,7 @@ Object *godot_icall_Object_Ctor(MonoObject *p_obj) { void godot_icall_Object_Disposed(MonoObject *p_obj, Object *p_ptr) { #ifdef DEBUG_ENABLED - CRASH_COND(p_ptr == NULL); + CRASH_COND(p_ptr == nullptr); #endif if (p_ptr->get_script_instance()) { @@ -59,7 +59,7 @@ void godot_icall_Object_Disposed(MonoObject *p_obj, Object *p_ptr) { if (cs_instance) { if (!cs_instance->is_destructing_script_instance()) { cs_instance->mono_object_disposed(p_obj); - p_ptr->set_script_instance(NULL); + p_ptr->set_script_instance(nullptr); } return; } @@ -70,8 +70,8 @@ void godot_icall_Object_Disposed(MonoObject *p_obj, Object *p_ptr) { if (data) { CSharpScriptBinding &script_binding = ((Map<Object *, CSharpScriptBinding>::Element *)data)->get(); if (script_binding.inited) { - Ref<MonoGCHandle> &gchandle = script_binding.gchandle; - if (gchandle.is_valid()) { + MonoGCHandleData &gchandle = script_binding.gchandle; + if (!gchandle.is_released()) { CSharpLanguage::release_script_gchandle(p_obj, gchandle); } } @@ -80,7 +80,7 @@ void godot_icall_Object_Disposed(MonoObject *p_obj, Object *p_ptr) { void godot_icall_Reference_Disposed(MonoObject *p_obj, Object *p_ptr, MonoBoolean p_is_finalizer) { #ifdef DEBUG_ENABLED - CRASH_COND(p_ptr == NULL); + CRASH_COND(p_ptr == nullptr); // This is only called with Reference derived classes CRASH_COND(!Object::cast_to<Reference>(p_ptr)); #endif @@ -99,7 +99,7 @@ void godot_icall_Reference_Disposed(MonoObject *p_obj, Object *p_ptr, MonoBoolea if (delete_owner) { memdelete(ref); } else if (remove_script_instance) { - ref->set_script_instance(NULL); + ref->set_script_instance(nullptr); } } return; @@ -117,8 +117,8 @@ void godot_icall_Reference_Disposed(MonoObject *p_obj, Object *p_ptr, MonoBoolea if (data) { CSharpScriptBinding &script_binding = ((Map<Object *, CSharpScriptBinding>::Element *)data)->get(); if (script_binding.inited) { - Ref<MonoGCHandle> &gchandle = script_binding.gchandle; - if (gchandle.is_valid()) { + MonoGCHandleData &gchandle = script_binding.gchandle; + if (!gchandle.is_released()) { CSharpLanguage::release_script_gchandle(p_obj, gchandle); } } @@ -126,37 +126,44 @@ void godot_icall_Reference_Disposed(MonoObject *p_obj, Object *p_ptr, MonoBoolea } } -MethodBind *godot_icall_Object_ClassDB_get_method(MonoString *p_type, MonoString *p_method) { - StringName type(GDMonoMarshal::mono_string_to_godot(p_type)); +void godot_icall_Object_ConnectEventSignals(Object *p_ptr) { + CSharpInstance *csharp_instance = CAST_CSHARP_INSTANCE(p_ptr->get_script_instance()); + if (csharp_instance) { + csharp_instance->connect_event_signals(); + } +} + +MethodBind *godot_icall_Object_ClassDB_get_method(StringName *p_type, MonoString *p_method) { + StringName type = p_type ? *p_type : StringName(); StringName method(GDMonoMarshal::mono_string_to_godot(p_method)); return ClassDB::get_method(type, method); } -MonoObject *godot_icall_Object_weakref(Object *p_obj) { - if (!p_obj) - return NULL; +MonoObject *godot_icall_Object_weakref(Object *p_ptr) { + if (!p_ptr) + return nullptr; Ref<WeakRef> wref; - Reference *ref = Object::cast_to<Reference>(p_obj); + Reference *ref = Object::cast_to<Reference>(p_ptr); if (ref) { REF r = ref; if (!r.is_valid()) - return NULL; + return nullptr; wref.instance(); wref->set_ref(r); } else { wref.instance(); - wref->set_obj(p_obj); + wref->set_obj(p_ptr); } return GDMonoUtils::unmanaged_get_managed(wref.ptr()); } -Error godot_icall_SignalAwaiter_connect(Object *p_source, MonoString *p_signal, Object *p_target, MonoObject *p_awaiter) { - String signal = GDMonoMarshal::mono_string_to_godot(p_signal); - return SignalAwaiterUtils::connect_signal_awaiter(p_source, signal, p_target, p_awaiter); +Error godot_icall_SignalAwaiter_connect(Object *p_source, StringName *p_signal, Object *p_target, MonoObject *p_awaiter) { + StringName signal = p_signal ? *p_signal : StringName(); + return gd_mono_connect_signal_awaiter(p_source, signal, p_target, p_awaiter); } MonoArray *godot_icall_DynamicGodotObject_SetMemberList(Object *p_ptr) { @@ -223,10 +230,10 @@ MonoBoolean godot_icall_DynamicGodotObject_SetMember(Object *p_ptr, MonoString * MonoString *godot_icall_Object_ToString(Object *p_ptr) { #ifdef DEBUG_ENABLED // Cannot happen in C#; would get an ObjectDisposedException instead. - CRASH_COND(p_ptr == NULL); + CRASH_COND(p_ptr == nullptr); #endif - - String result = p_ptr->to_string(); + // Can't call 'Object::to_string()' here, as that can end up calling 'ToString' again resulting in an endless circular loop. + String result = "[" + p_ptr->get_class() + ":" + itos(p_ptr->get_instance_id()) + "]"; return GDMonoMarshal::mono_string_from_godot(result); } |