diff options
author | Juan Linietsky <reduzio@gmail.com> | 2018-05-07 17:30:03 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2018-05-07 17:30:03 -0300 |
commit | ff1e7cfbf4b7ad9b327588ce7dffb43d31fee3e9 (patch) | |
tree | d28b0690a6e921a044f2fa82e2091a5b411ea439 /modules | |
parent | 80b9edf0f69107d88aecd4df3783f20eb1b17dd5 (diff) |
Add is_instance_valid() method to GDScript, ending more than a decade of pain.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gdscript/gdscript_functions.cpp | 18 | ||||
-rw-r--r-- | modules/gdscript/gdscript_functions.h | 1 |
2 files changed, 18 insertions, 1 deletions
diff --git a/modules/gdscript/gdscript_functions.cpp b/modules/gdscript/gdscript_functions.cpp index 278585cb01..8d25dfec0d 100644 --- a/modules/gdscript/gdscript_functions.cpp +++ b/modules/gdscript/gdscript_functions.cpp @@ -122,6 +122,7 @@ const char *GDScriptFunctions::get_func_name(Function p_func) { "print_stack", "instance_from_id", "len", + "is_instance_valid", }; return _names[p_func]; @@ -1277,6 +1278,17 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ } } break; + case IS_INSTANCE_VALID: { + + VALIDATE_ARG_COUNT(1); + if (p_args[0]->get_type() != Variant::OBJECT) { + r_ret = false; + } else { + Object *obj = *p_args[0]; + r_ret = ObjectDB::instance_validate(obj); + } + + } break; case FUNC_MAX: { ERR_FAIL(); @@ -1798,7 +1810,11 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) { mi.return_val.type = Variant::INT; return mi; } break; - + case IS_INSTANCE_VALID: { + MethodInfo mi("is_instance_valid", PropertyInfo(Variant::OBJECT, "instance")); + mi.return_val.type = Variant::BOOL; + return mi; + } break; case FUNC_MAX: { ERR_FAIL_V(MethodInfo()); diff --git a/modules/gdscript/gdscript_functions.h b/modules/gdscript/gdscript_functions.h index 1d54006084..c4731d17a4 100644 --- a/modules/gdscript/gdscript_functions.h +++ b/modules/gdscript/gdscript_functions.h @@ -113,6 +113,7 @@ public: PRINT_STACK, INSTANCE_FROM_ID, LEN, + IS_INSTANCE_VALID, FUNC_MAX }; |