66 */
77
88use super :: { make_callable_name, make_godot_fn} ;
9- use crate :: builtin:: { Callable , GString , Variant } ;
9+ #[ cfg( feature = "experimental-threads" ) ]
10+ use crate :: builtin:: Callable ;
11+ use crate :: builtin:: { GString , Variant } ;
1012use crate :: classes:: object:: ConnectFlags ;
1113use crate :: meta;
1214use crate :: meta:: InParamTuple ;
@@ -125,13 +127,14 @@ where
125127 fn inner_connect_godot_fn < F > (
126128 self ,
127129 godot_fn : impl FnMut ( & [ & Variant ] ) -> Result < Variant , ( ) > + ' static ,
130+ bound : & Gd < impl GodotClass > ,
128131 ) -> ConnectHandle {
129132 let callable_name = match & self . data . callable_name {
130133 Some ( user_provided_name) => user_provided_name,
131134 None => & make_callable_name :: < F > ( ) ,
132135 } ;
133136
134- let callable = Callable :: from_local_fn ( callable_name, godot_fn) ;
137+ let callable = bound . linked_callable ( callable_name, godot_fn) ;
135138 self . parent_sig
136139 . inner_connect_untyped ( callable, self . data . connect_flags )
137140 }
@@ -165,7 +168,8 @@ impl<C: WithSignals, Ps: InParamTuple + 'static> ConnectBuilder<'_, '_, C, Ps> {
165168 . call ( ( ) , args) ;
166169 } ) ;
167170
168- self . inner_connect_godot_fn :: < F > ( godot_fn)
171+ let bound = self . parent_sig . receiver_object ( ) ;
172+ self . inner_connect_godot_fn :: < F > ( godot_fn, & bound)
169173 }
170174
171175 /// Connect a method with `&mut self` as the first parameter (user classes only).
@@ -191,7 +195,8 @@ impl<C: WithSignals, Ps: InParamTuple + 'static> ConnectBuilder<'_, '_, C, Ps> {
191195 . call ( & mut * guard, args) ;
192196 } ) ;
193197
194- self . inner_connect_godot_fn :: < F > ( godot_fn)
198+ let bound = self . parent_sig . receiver_object ( ) ;
199+ self . inner_connect_godot_fn :: < F > ( godot_fn, & bound)
195200 }
196201
197202 /// Connect a method with `&mut Gd<Self>` as the first parameter (user + engine classes).
@@ -208,14 +213,15 @@ impl<C: WithSignals, Ps: InParamTuple + 'static> ConnectBuilder<'_, '_, C, Ps> {
208213 for < ' c_rcv > IndirectSignalReceiver < ' c_rcv , Gd < C > , Ps , F > : From < & ' c_rcv mut F > ,
209214 {
210215 let gd = self . parent_sig . receiver_object ( ) ;
216+ let bound = gd. clone ( ) ;
211217
212218 let godot_fn = make_godot_fn ( move |args| {
213219 IndirectSignalReceiver :: from ( & mut function)
214220 . function ( )
215221 . call ( gd. clone ( ) , args) ;
216222 } ) ;
217223
218- self . inner_connect_godot_fn :: < F > ( godot_fn)
224+ self . inner_connect_godot_fn :: < F > ( godot_fn, & bound )
219225 }
220226
221227 /// Connect a method with any `&mut OtherC` as the first parameter (user classes only).
@@ -250,7 +256,7 @@ impl<C: WithSignals, Ps: InParamTuple + 'static> ConnectBuilder<'_, '_, C, Ps> {
250256 . call ( & mut * guard, args) ;
251257 } ) ;
252258
253- self . inner_connect_godot_fn :: < F > ( godot_fn)
259+ self . inner_connect_godot_fn :: < F > ( godot_fn, & object . to_signal_obj ( ) )
254260 }
255261
256262 /// Connect a method with any `&mut Gd<OtherC>` as the first parameter (user + engine classes).
@@ -282,7 +288,7 @@ impl<C: WithSignals, Ps: InParamTuple + 'static> ConnectBuilder<'_, '_, C, Ps> {
282288 . call ( gd. clone ( ) , args) ;
283289 } ) ;
284290
285- self . inner_connect_godot_fn :: < F > ( godot_fn)
291+ self . inner_connect_godot_fn :: < F > ( godot_fn, & object . to_signal_obj ( ) )
286292 }
287293
288294 /// Connect to this signal using a thread-safe function, allows the signal to be called across threads.
0 commit comments