Skip to content

Commit a355192

Browse files
committed
Add example for untyped signal connect
1 parent 85513fa commit a355192

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/register/signals.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,16 +443,25 @@ The builder methods need to be called in the correct order ("stages"). See [API
443443

444444
Godot's low-level APIs for dealing with untyped signals are still available:
445445

446-
- [`Object::connect()`][api-object-connect], `Object::connect_ex()`
446+
- [`Object::connect()`][api-object-connect]
447+
- [`Object::connect_ex()`][api-object-connect-ex]
447448
- [`Object::emit_signal()`][api-object-emitsignal]
448449
- [`Signal::connect()`][api-signal-connect]
449450
- [`Signal::emit()`][api-signal-emit]
450451

451452
The new typed-signal API should cover the full functionality, but there are situations where information is only available at runtime, making
452453
the untyped reflection APIs a good fit. We might also combine the two in the future.
453454

454-
To emit an untyped signal, you can call the `Object::emit_signal` method by accessing the base class (mutably):
455-
Considering the `Monster` struct from the previous examples, you can emit its signal with:
455+
One way to connect signals the old-school is passing in the signal name and the `Callable`:
456+
457+
```rust
458+
let monster: Gd<Monster> = ...;
459+
let damage_taken: Callable = monster.callable("damage_taken");
460+
monster.connect("damage_taken", &damage_taken);
461+
```
462+
463+
To emit an untyped signal, call the `Object::emit_signal()` method by (mutably) accessing the base class.
464+
Staying with the `Monster` struct from the previous examples, you can emit its signal with:
456465

457466
```rust
458467
self.base_mut().emit_signal(
@@ -461,10 +470,11 @@ self.base_mut().emit_signal(
461470
);
462471
```
463472

464-
See [vslice!][api-vslice] docs for passing multiple variants in a slice.
473+
See [`vslice!`][api-vslice] docs for passing multiple variants in a slice.
465474

466-
Certain typed-signal features are still planned and will make working with signals even more streamlined. Other features are likely not going
467-
to be ported to godot-rust, e.g. a `Callable::bind()` equivalent for typed Rust methods. Just use closures instead.
475+
Certain untyped-signal functionality may still be ported typed signals, while others such as `Callable::bind()` will likely not be available.
476+
Just use closures instead. Generally speaking, the [`TypedSignal`][api-typedsignal] and [`ConnectBuilder`][api-connectbuilder] APIs are designed
477+
to be extensible for your own workflows.
468478

469479

470480
## Conclusion
@@ -483,6 +493,7 @@ Rust function references or closures can be directly connected to signals, and e
483493
[api-typedsignal-builder]: https://godot-rust.github.io/docs/gdext/master/godot/register/struct.TypedSignal.html#method.builder
484494
[api-connectbuilder]: https://godot-rust.github.io/docs/gdext/master/godot/register/struct.ConnectBuilder.html
485495
[api-object-connect]: https://godot-rust.github.io/docs/gdext/master/godot/classes/struct.Object.html#method.connect
496+
[api-object-connect-ex]: https://godot-rust.github.io/docs/gdext/master/godot/classes/struct.Object.html#method.connect_ex
486497
[api-object-emitsignal]: https://godot-rust.github.io/docs/gdext/master/godot/classes/struct.Object.html#method.emit_signal
487498
[api-signal-connect]: https://godot-rust.github.io/docs/gdext/master/godot/builtin/struct.Signal.html#method.connect
488499
[api-signal-emit]: https://godot-rust.github.io/docs/gdext/master/godot/builtin/struct.Signal.html#method.emit

0 commit comments

Comments
 (0)