Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implements #586.
See also previous discussion on #584.
TL;DR
This PR adds a new
@Signal
macro, giving a cleaner and more consistent way to add user-defined signals from Swift.These signals can be used in the same way as built-in signals:
Motivation
The existing
#signal
macro defines the signal as a static property on the class that contains it.This is different from the generated implementation of built-in signals, and means that we have to use a different syntax to work with them -- which feels... non-optimal.
Implementation
We add a new
@Signal
macro expansion which generates a computed property on the class, usingGenericSignal
.This is the same approach that is used to implement the signals imported from the Godot API.
We also add an
emit()
method toGenericSignal
, which is of course essential to support emitting signals defined in Swift.We add
SimpleSignal
andSignalWithArguments
as slightly clearer aliases forGenericSignal
This change should be 100% additive, and should not break the old
#signal
macro.To Do
If this change is adopted, it's probably worth updating the documentation and deprecating the old macro.