Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion godot-codegen/src/generator/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fn make_with_signals_impl(

// Used outside, to document class with links to this type.
pub fn make_collection_name(class_name: &TyName) -> Ident {
format_ident!("SignalsIn{}", class_name.rust_ty)
format_ident!("SignalsOf{}", class_name.rust_ty)
}

fn make_individual_struct_name(signal_name: &str) -> Ident {
Expand Down
14 changes: 8 additions & 6 deletions godot-core/src/registry/signal/connect_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ macro_rules! impl_builder_connect {
F: FnMut(&mut C, $($Ps),*) -> R + 'static,
{
let mut gd = self.parent_sig.receiver_object();

let godot_fn = make_godot_fn(move |($($args,)*): ($($Ps,)*)| {
let mut guard = Gd::bind_mut(&mut gd);
function(&mut *guard, $($args),*);
Expand All @@ -201,11 +202,12 @@ macro_rules! impl_builder_connect {
/// - If you need cross-thread signals, use [`connect_sync()`](#method.connect_sync) instead (requires feature `experimental-threads`).
pub fn connect_self_gd<F, R>(self, mut function: F)
where
F: FnMut(&mut Gd<C>, $($Ps),*) -> R + 'static,
F: FnMut(Gd<C>, $($Ps),*) -> R + 'static,
{
let mut gd = self.parent_sig.receiver_object();
let gd = self.parent_sig.receiver_object();

let godot_fn = make_godot_fn(move |($($args,)*): ($($Ps,)*)| {
function(&mut gd, $($args),*);
function(gd.clone(), $($args),*);
});

self.inner_connect_godot_fn::<F>(godot_fn);
Expand Down Expand Up @@ -253,12 +255,12 @@ macro_rules! impl_builder_connect {
pub fn connect_other_gd<F, R, OtherC>(self, object: &impl ToSignalObj<OtherC>, mut method: F)
where
OtherC: GodotClass,
F: FnMut(&mut Gd<OtherC>, $($Ps),*) -> R + 'static,
F: FnMut(Gd<OtherC>, $($Ps),*) -> R + 'static,
{
let mut gd = object.to_signal_obj();
let gd = object.to_signal_obj();

let godot_fn = make_godot_fn(move |($($args,)*): ($($Ps,)*)| {
method(&mut gd, $($args),*);
method(gd.clone(), $($args),*);
});

self.inner_connect_godot_fn::<F>(godot_fn);
Expand Down
17 changes: 13 additions & 4 deletions itest/rust/src/builtin_tests/containers/signal_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ fn signal_symbols_internal() {
// Check that closure is invoked.
assert_eq!(tracker.get(), 1234, "Emit failed (closure)");

// Check that instance method is invoked.
// Check that instance methods self_receive() and self_receive_gd_inc1() are invoked.
assert_eq!(
emitter.bind().last_received_int,
1234,
1234 + 1, // self_receive_gd_inc1() increments by 1, and should be called after self_receive().
"Emit failed (method)"
);

Expand Down Expand Up @@ -400,7 +400,7 @@ fn signal_symbols_connect_inferred() {
.tree_exiting()
.builder()
.flags(ConnectFlags::DEFERRED)
.connect_self_gd(|this| {
.connect_self_gd(|mut this| {
// Use methods that `Node` declares.
let _ = this.get_path(); // ref.
this.set_unique_name_in_owner(true); // mut.
Expand All @@ -422,7 +422,7 @@ fn signal_symbols_connect_inferred() {
.signals()
.tree_exiting()
.builder()
.connect_other_gd(&user, |this| {
.connect_other_gd(&user, |mut this| {
// Use methods that `Node` declares.
let _ = this.get_path(); // ref.
this.set_unique_name_in_owner(true); // mut.
Expand Down Expand Up @@ -513,6 +513,14 @@ mod emitter {
}
}

#[func]
pub fn self_receive_gd_inc1(mut this: Gd<Self>, _arg1: i64) {
#[cfg(since_api = "4.2")]
{
this.bind_mut().last_received_int += 1;
}
}

#[func]
pub fn self_receive_constant(&mut self) {
#[cfg(since_api = "4.2")]
Expand All @@ -534,6 +542,7 @@ mod emitter {
sig.connect_self(Self::self_receive);
sig.connect(Self::self_receive_static);
sig.connect(move |i| tracker.set(i));
sig.builder().connect_self_gd(Self::self_receive_gd_inc1);
}

#[cfg(since_api = "4.2")]
Expand Down
Loading