diff options
author | Juan Linietsky <reduzio@gmail.com> | 2020-10-10 08:24:14 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-10 08:24:14 -0300 |
commit | cf0045011ed8f1b79e3c3012dc2aeb3a49d85363 (patch) | |
tree | 7b924010b4696f108d022323ce70371a44043847 /core/callable.cpp | |
parent | ca2c0b8937d287e608448a9a5ba553a8deaf46d9 (diff) | |
parent | 351a122029fea57f431672965d623f34262d6e11 (diff) |
Merge pull request #42683 from reduz/implement-call-bind-unbind
Add ability to bind an unbind arguments to Callable.
Diffstat (limited to 'core/callable.cpp')
-rw-r--r-- | core/callable.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/core/callable.cpp b/core/callable.cpp index b7bdc715f8..c368565687 100644 --- a/core/callable.cpp +++ b/core/callable.cpp @@ -30,6 +30,7 @@ #include "callable.h" +#include "callable_bind.h" #include "core/script_language.h" #include "message_queue.h" #include "object.h" @@ -53,6 +54,18 @@ void Callable::call(const Variant **p_arguments, int p_argcount, Variant &r_retu } } +Callable Callable::bind(const Variant **p_arguments, int p_argcount) const { + Vector<Variant> args; + args.resize(p_argcount); + for (int i = 0; i < p_argcount; i++) { + args.write[i] = *p_arguments[i]; + } + return Callable(memnew(CallableCustomBind(*this, args))); +} +Callable Callable::unbind(int p_argcount) const { + return Callable(memnew(CallableCustomUnbind(*this, p_argcount))); +} + Object *Callable::get_object() const { if (is_null()) { return nullptr; @@ -85,6 +98,18 @@ CallableCustom *Callable::get_custom() const { return custom; } +const Callable *Callable::get_base_comparator() const { + const Callable *comparator = nullptr; + if (is_custom()) { + comparator = custom->get_base_comparator(); + } + if (comparator) { + return comparator; + } else { + return this; + } +} + uint32_t Callable::hash() const { if (is_custom()) { return custom->hash(); @@ -258,6 +283,10 @@ Callable::~Callable() { } } +const Callable *CallableCustom::get_base_comparator() const { + return nullptr; +} + CallableCustom::CallableCustom() { ref_count.init(); } |