From 7bf5fc709e7efe4bd23d8986e72165f51c945402 Mon Sep 17 00:00:00 2001 From: kobewi Date: Sun, 19 Sep 2021 18:55:23 +0200 Subject: [PATCH] Remove binds from Signal.connect --- core/variant/callable.cpp | 4 ++-- core/variant/callable.h | 2 +- core/variant/variant_call.cpp | 2 +- doc/classes/Signal.xml | 12 +++++++++--- modules/gdscript/gdscript_vm.cpp | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/core/variant/callable.cpp b/core/variant/callable.cpp index f487e718f4c..dcded6e61f5 100644 --- a/core/variant/callable.cpp +++ b/core/variant/callable.cpp @@ -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 &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) { diff --git a/core/variant/callable.h b/core/variant/callable.h index 52094af3aa2..de886492ea6 100644 --- a/core/variant/callable.h +++ b/core/variant/callable.h @@ -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 &p_binds = Vector(), 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; diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 49a0b455dfe..5c43be741e1 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -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()); diff --git a/doc/classes/Signal.xml b/doc/classes/Signal.xml index 11107c093d9..3845b3f20db 100644 --- a/doc/classes/Signal.xml +++ b/doc/classes/Signal.xml @@ -32,10 +32,16 @@ - - + - 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] diff --git a/modules/gdscript/gdscript_vm.cpp b/modules/gdscript/gdscript_vm.cpp index bf21c8510a2..9ea9fc61def 100644 --- a/modules/gdscript/gdscript_vm.cpp +++ b/modules/gdscript/gdscript_vm.cpp @@ -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;