|
@@ -30,10 +30,11 @@
|
|
|
|
|
|
#include "callable.h"
|
|
#include "callable.h"
|
|
|
|
|
|
-#include "callable_bind.h"
|
|
|
|
#include "core/object/object.h"
|
|
#include "core/object/object.h"
|
|
#include "core/object/ref_counted.h"
|
|
#include "core/object/ref_counted.h"
|
|
#include "core/object/script_language.h"
|
|
#include "core/object/script_language.h"
|
|
|
|
+#include "core/variant/callable_bind.h"
|
|
|
|
+#include "core/variant/variant_callable.h"
|
|
|
|
|
|
void Callable::call_deferredp(const Variant **p_arguments, int p_argcount) const {
|
|
void Callable::call_deferredp(const Variant **p_arguments, int p_argcount) const {
|
|
MessageQueue::get_singleton()->push_callablep(*this, p_arguments, p_argcount, true);
|
|
MessageQueue::get_singleton()->push_callablep(*this, p_arguments, p_argcount, true);
|
|
@@ -327,14 +328,27 @@ Callable::operator String() const {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+Callable Callable::create(const Variant &p_variant, const StringName &p_method) {
|
|
|
|
+ ERR_FAIL_COND_V_MSG(p_method == StringName(), Callable(), "Method argument to Callable::create method must be a non-empty string.");
|
|
|
|
+
|
|
|
|
+ switch (p_variant.get_type()) {
|
|
|
|
+ case Variant::NIL:
|
|
|
|
+ return Callable(ObjectID(), p_method);
|
|
|
|
+ case Variant::OBJECT:
|
|
|
|
+ return Callable(p_variant.operator ObjectID(), p_method);
|
|
|
|
+ default:
|
|
|
|
+ return Callable(memnew(VariantCallable(p_variant, p_method)));
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
Callable::Callable(const Object *p_object, const StringName &p_method) {
|
|
Callable::Callable(const Object *p_object, const StringName &p_method) {
|
|
- if (p_method == StringName()) {
|
|
|
|
|
|
+ if (unlikely(p_method == StringName())) {
|
|
object = 0;
|
|
object = 0;
|
|
- ERR_FAIL_MSG("Method argument to Callable constructor must be a non-empty string");
|
|
|
|
|
|
+ ERR_FAIL_MSG("Method argument to Callable constructor must be a non-empty string.");
|
|
}
|
|
}
|
|
- if (p_object == nullptr) {
|
|
|
|
|
|
+ if (unlikely(p_object == nullptr)) {
|
|
object = 0;
|
|
object = 0;
|
|
- ERR_FAIL_MSG("Object argument to Callable constructor must be non-null");
|
|
|
|
|
|
+ ERR_FAIL_MSG("Object argument to Callable constructor must be non-null.");
|
|
}
|
|
}
|
|
|
|
|
|
object = p_object->get_instance_id();
|
|
object = p_object->get_instance_id();
|
|
@@ -342,9 +356,9 @@ Callable::Callable(const Object *p_object, const StringName &p_method) {
|
|
}
|
|
}
|
|
|
|
|
|
Callable::Callable(ObjectID p_object, const StringName &p_method) {
|
|
Callable::Callable(ObjectID p_object, const StringName &p_method) {
|
|
- if (p_method == StringName()) {
|
|
|
|
|
|
+ if (unlikely(p_method == StringName())) {
|
|
object = 0;
|
|
object = 0;
|
|
- ERR_FAIL_MSG("Method argument to Callable constructor must be a non-empty string");
|
|
|
|
|
|
+ ERR_FAIL_MSG("Method argument to Callable constructor must be a non-empty string.");
|
|
}
|
|
}
|
|
|
|
|
|
object = p_object;
|
|
object = p_object;
|
|
@@ -352,9 +366,9 @@ Callable::Callable(ObjectID p_object, const StringName &p_method) {
|
|
}
|
|
}
|
|
|
|
|
|
Callable::Callable(CallableCustom *p_custom) {
|
|
Callable::Callable(CallableCustom *p_custom) {
|
|
- if (p_custom->referenced) {
|
|
|
|
|
|
+ if (unlikely(p_custom->referenced)) {
|
|
object = 0;
|
|
object = 0;
|
|
- ERR_FAIL_MSG("Callable custom is already referenced");
|
|
|
|
|
|
+ ERR_FAIL_MSG("Callable custom is already referenced.");
|
|
}
|
|
}
|
|
p_custom->referenced = true;
|
|
p_custom->referenced = true;
|
|
object = 0; //ensure object is all zero, since pointer may be 32 bits
|
|
object = 0; //ensure object is all zero, since pointer may be 32 bits
|