Remove binds from Signal.connect

This commit is contained in:
kobewi 2021-09-19 18:55:23 +02:00
parent 0e5b0c025c
commit 7bf5fc709e
5 changed files with 14 additions and 8 deletions

View file

@ -377,11 +377,11 @@ Error Signal::emit(const Variant **p_arguments, int p_argcount) const {
return obj->emit_signal(name, p_arguments, p_argcount);
}
Error Signal::connect(const Callable &p_callable, const Vector<Variant> &p_binds, uint32_t p_flags) {
Error Signal::connect(const Callable &p_callable, uint32_t p_flags) {
Object *object = get_object();
ERR_FAIL_COND_V(!object, ERR_UNCONFIGURED);
return object->connect(name, p_callable, p_binds, p_flags);
return object->connect(name, p_callable, varray(), p_flags);
}
void Signal::disconnect(const Callable &p_callable) {

View file

@ -159,7 +159,7 @@ public:
operator String() const;
Error emit(const Variant **p_arguments, int p_argcount) const;
Error connect(const Callable &p_callable, const Vector<Variant> &p_binds = Vector<Variant>(), uint32_t p_flags = 0);
Error connect(const Callable &p_callable, uint32_t p_flags = 0);
void disconnect(const Callable &p_callable);
bool is_connected(const Callable &p_callable) const;

View file

@ -1688,7 +1688,7 @@ static void _register_variant_builtin_methods() {
bind_method(Signal, get_object_id, sarray(), varray());
bind_method(Signal, get_name, sarray(), varray());
bind_method(Signal, connect, sarray("callable", "binds", "flags"), varray(Array(), 0));
bind_method(Signal, connect, sarray("callable", "flags"), varray(0));
bind_method(Signal, disconnect, sarray("callable"), varray());
bind_method(Signal, is_connected, sarray("callable"), varray());
bind_method(Signal, get_connections, sarray(), varray());

View file

@ -32,10 +32,16 @@
<method name="connect">
<return type="int" />
<argument index="0" name="callable" type="Callable" />
<argument index="1" name="binds" type="Array" default="[]" />
<argument index="2" name="flags" type="int" default="0" />
<argument index="1" name="flags" type="int" default="0" />
<description>
Connects this signal to the specified [Callable], optionally providing binds and connection flags.
Connects this signal to the specified [Callable], optionally providing connection flags. You can provide additional arguments to the connected method call by using [method Callable.bind].
[codeblock]
for button in $Buttons.get_children():
button.pressed.connect(on_pressed.bind(button))
func on_pressed(button):
print(button.name, " was pressed")
[/codeblock]
</description>
</method>
<method name="disconnect">

View file

@ -2138,7 +2138,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
retvalue = gdfs;
Error err = sig.connect(Callable(gdfs.ptr(), "_signal_callback"), varray(gdfs), Object::CONNECT_ONESHOT);
Error err = sig.connect(callable_bind(Callable(gdfs.ptr(), "_signal_callback"), retvalue), Object::CONNECT_ONESHOT);
if (err != OK) {
err_text = "Error connecting to signal: " + sig.get_name() + " during await.";
OPCODE_BREAK;