As an alternative, you can use Godot's dynamic API to register signals. The Object class has methods connect() and emit_signal() that can be used to connect and emit signals, respectively.
While there are quite a few places in the docs that describe how to declare a new signal using #[signal], there does not seem to be anywhere that shows you how to connect a signal to a callable. The link in the above passage to Object::connect() API docs contains the following docstring:
To set the default parameters, use Self::connect_ex and its builder methods. See the book for detailed usage instructions.
This links to the section on functions, which demonstrates how to call a function via Object::call(). However this does not generalize to Object::connect(), which expects a Callable argument rather than the impl AsArg<StringName> expected by Object::call().
I would like to define a function in rust via #[func], then connect it via Object::connect() to a signal. Ideally the book, API docs, or both would include an example of how this could be achieved.
Section in question: https://godot-rust.github.io/book/register/signals.html?highlight=connect#registering-signals
Specific region:
While there are quite a few places in the docs that describe how to declare a new signal using
#[signal]
, there does not seem to be anywhere that shows you how to connect a signal to a callable. The link in the above passage toObject::connect()
API docs contains the following docstring:This links to the section on functions, which demonstrates how to call a function via
Object::call()
. However this does not generalize toObject::connect()
, which expects aCallable
argument rather than theimpl AsArg<StringName>
expected byObject::call()
.I would like to define a function in rust via
#[func]
, then connect it viaObject::connect()
to a signal. Ideally the book, API docs, or both would include an example of how this could be achieved.