6
6
*/
7
7
8
8
use 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 } ;
10
12
use crate :: classes:: object:: ConnectFlags ;
11
13
use crate :: meta;
12
14
use crate :: meta:: InParamTuple ;
@@ -125,13 +127,14 @@ where
125
127
fn inner_connect_godot_fn < F > (
126
128
self ,
127
129
godot_fn : impl FnMut ( & [ & Variant ] ) -> Result < Variant , ( ) > + ' static ,
130
+ bound : & Gd < impl GodotClass > ,
128
131
) -> ConnectHandle {
129
132
let callable_name = match & self . data . callable_name {
130
133
Some ( user_provided_name) => user_provided_name,
131
134
None => & make_callable_name :: < F > ( ) ,
132
135
} ;
133
136
134
- let callable = Callable :: from_local_fn ( callable_name, godot_fn) ;
137
+ let callable = bound . linked_callable ( callable_name, godot_fn) ;
135
138
self . parent_sig
136
139
. inner_connect_untyped ( callable, self . data . connect_flags )
137
140
}
@@ -165,7 +168,8 @@ impl<C: WithSignals, Ps: InParamTuple + 'static> ConnectBuilder<'_, '_, C, Ps> {
165
168
. call ( ( ) , args) ;
166
169
} ) ;
167
170
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)
169
173
}
170
174
171
175
/// 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> {
191
195
. call ( & mut * guard, args) ;
192
196
} ) ;
193
197
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)
195
200
}
196
201
197
202
/// 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> {
208
213
for < ' c_rcv > IndirectSignalReceiver < ' c_rcv , Gd < C > , Ps , F > : From < & ' c_rcv mut F > ,
209
214
{
210
215
let gd = self . parent_sig . receiver_object ( ) ;
216
+ let bound = gd. clone ( ) ;
211
217
212
218
let godot_fn = make_godot_fn ( move |args| {
213
219
IndirectSignalReceiver :: from ( & mut function)
214
220
. function ( )
215
221
. call ( gd. clone ( ) , args) ;
216
222
} ) ;
217
223
218
- self . inner_connect_godot_fn :: < F > ( godot_fn)
224
+ self . inner_connect_godot_fn :: < F > ( godot_fn, & bound )
219
225
}
220
226
221
227
/// 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> {
250
256
. call ( & mut * guard, args) ;
251
257
} ) ;
252
258
253
- self . inner_connect_godot_fn :: < F > ( godot_fn)
259
+ self . inner_connect_godot_fn :: < F > ( godot_fn, & object . to_signal_obj ( ) )
254
260
}
255
261
256
262
/// 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> {
282
288
. call ( gd. clone ( ) , args) ;
283
289
} ) ;
284
290
285
- self . inner_connect_godot_fn :: < F > ( godot_fn)
291
+ self . inner_connect_godot_fn :: < F > ( godot_fn, & object . to_signal_obj ( ) )
286
292
}
287
293
288
294
/// Connect to this signal using a thread-safe function, allows the signal to be called across threads.
0 commit comments