summaryrefslogtreecommitdiff
path: root/modules/gdscript
diff options
context:
space:
mode:
authorPedro J. Estébanez <pedrojrulez@gmail.com>2017-05-17 14:47:17 +0200
committerPedro J. Estébanez <pedrojrulez@gmail.com>2017-05-17 14:55:59 +0200
commitb69d4ebff40c4b8fc55db00ad84514aff48f0c5d (patch)
treec09d9bfb6b4ea8a2a945e4ac8a64d53961a7ff81 /modules/gdscript
parent9fa4f1c54c6d528192e7ed04354d5ce2c733d99a (diff)
Add extended check option to GDFunctionState::is_valid()
Diffstat (limited to 'modules/gdscript')
-rw-r--r--modules/gdscript/gd_function.cpp18
-rw-r--r--modules/gdscript/gd_function.h2
2 files changed, 16 insertions, 4 deletions
diff --git a/modules/gdscript/gd_function.cpp b/modules/gdscript/gd_function.cpp
index 608256c88a..fb32d23ad5 100644
--- a/modules/gdscript/gd_function.cpp
+++ b/modules/gdscript/gd_function.cpp
@@ -1433,9 +1433,21 @@ Variant GDFunctionState::_signal_callback(const Variant **p_args, int p_argcount
return ret;
}
-bool GDFunctionState::is_valid() const {
+bool GDFunctionState::is_valid(bool p_extended_check) const {
+
+ if (function == NULL)
+ return false;
+
+ if (p_extended_check) {
+ //class instance gone?
+ if (state.instance_id && !ObjectDB::get_instance(state.instance_id))
+ return false;
+ //script gone?
+ if (state.script_id && !ObjectDB::get_instance(state.script_id))
+ return false;
+ }
- return function != NULL;
+ return true;
}
Variant GDFunctionState::resume(const Variant &p_arg) {
@@ -1464,7 +1476,7 @@ Variant GDFunctionState::resume(const Variant &p_arg) {
void GDFunctionState::_bind_methods() {
ClassDB::bind_method(D_METHOD("resume:Variant", "arg"), &GDFunctionState::resume, DEFVAL(Variant()));
- ClassDB::bind_method(D_METHOD("is_valid"), &GDFunctionState::is_valid);
+ ClassDB::bind_method(D_METHOD("is_valid", "extended_check"), &GDFunctionState::is_valid, DEFVAL(false));
ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "_signal_callback", &GDFunctionState::_signal_callback, MethodInfo("_signal_callback"));
}
diff --git a/modules/gdscript/gd_function.h b/modules/gdscript/gd_function.h
index f0bf33147b..6d20b19777 100644
--- a/modules/gdscript/gd_function.h
+++ b/modules/gdscript/gd_function.h
@@ -237,7 +237,7 @@ protected:
static void _bind_methods();
public:
- bool is_valid() const;
+ bool is_valid(bool p_extended_check = false) const;
Variant resume(const Variant &p_arg = Variant());
GDFunctionState();
~GDFunctionState();