diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2019-10-01 10:35:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-01 10:35:37 +0200 |
commit | d66d970fdbf28a09057dfc671c922ba3b5c23773 (patch) | |
tree | 06ff25041ca186b12a54e69607525fa21a0b8c68 | |
parent | e695ac6e7b70332fe88e37559f3aa345aace8b24 (diff) | |
parent | 628f46760512a5bd4e318a86fa62e7d0cdf0e394 (diff) | |
download | redot-engine-d66d970fdbf28a09057dfc671c922ba3b5c23773.tar.gz |
Merge pull request #32172 from WindyDarian/gdscript_allow_null_weakref
Allow weakref(null) in gdscript
-rw-r--r-- | modules/gdscript/gdscript_functions.cpp | 44 |
1 files changed, 19 insertions, 25 deletions
diff --git a/modules/gdscript/gdscript_functions.cpp b/modules/gdscript/gdscript_functions.cpp index 97790e00bb..d9535d0f1f 100644 --- a/modules/gdscript/gdscript_functions.cpp +++ b/modules/gdscript/gdscript_functions.cpp @@ -572,37 +572,31 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ } break; case OBJ_WEAKREF: { VALIDATE_ARG_COUNT(1); - if (p_args[0]->get_type() != Variant::OBJECT) { - + if (p_args[0]->get_type() == Variant::OBJECT) { + if (p_args[0]->is_ref()) { + Ref<WeakRef> wref = memnew(WeakRef); + REF r = *p_args[0]; + if (r.is_valid()) { + wref->set_ref(r); + } + r_ret = wref; + } else { + Ref<WeakRef> wref = memnew(WeakRef); + Object *obj = *p_args[0]; + if (obj) { + wref->set_obj(obj); + } + r_ret = wref; + } + } else if (p_args[0]->get_type() == Variant::NIL) { + r_ret = memnew(WeakRef); + } else { r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::OBJECT; r_ret = Variant(); return; } - - if (p_args[0]->is_ref()) { - - REF r = *p_args[0]; - if (!r.is_valid()) { - r_ret = Variant(); - return; - } - - Ref<WeakRef> wref = memnew(WeakRef); - wref->set_ref(r); - r_ret = wref; - } else { - Object *obj = *p_args[0]; - if (!obj) { - r_ret = Variant(); - return; - } - Ref<WeakRef> wref = memnew(WeakRef); - wref->set_obj(obj); - r_ret = wref; - } - } break; case FUNC_FUNCREF: { VALIDATE_ARG_COUNT(2); |