Skip to content

Commit 5fbab82

Browse files
committed
Fix emit() not being available on inherited symbols; test internal connect/emit
Also clean up some dead code.
1 parent c4b74c8 commit 5fbab82

File tree

4 files changed

+38
-19
lines changed

4 files changed

+38
-19
lines changed

godot-codegen/src/generator/signals.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,7 @@ fn make_signal_collection(
174174
let code = quote! {
175175
#[doc = #collection_docs]
176176
// C is needed for signals of derived classes that are upcast via Deref; C in that class is the derived class.
177-
pub struct #collection_struct_name<'c, C: WithSignals = #class_name>
178-
{
177+
pub struct #collection_struct_name<'c, C: WithSignals /* = #class_name */> {
179178
#[doc(hidden)]
180179
pub(crate) __internal_obj: Option<C::__SignalObj<'c>>,
181180
}
@@ -228,8 +227,8 @@ fn make_signal_individual_struct(signal: &ClassSignal, params: &SignalParams) ->
228227
..
229228
} = params;
230229

231-
let class_name = &signal.surrounding_class;
232-
let class_ty = quote! { #class_name };
230+
// let class_name = &signal.surrounding_class;
231+
// let class_ty = quote! { #class_name };
233232
let param_tuple = quote! { ( #type_list ) };
234233
let typed_name = format_ident!("Typed{}", individual_struct_name);
235234

@@ -238,11 +237,11 @@ fn make_signal_individual_struct(signal: &ClassSignal, params: &SignalParams) ->
238237
// Reduce tokens to parse by reusing this type definitions.
239238
type #typed_name<'c, C> = TypedSignal<'c, C, #param_tuple>;
240239

241-
pub struct #individual_struct_name<'c, C: WithSignals = #class_ty> {
240+
pub struct #individual_struct_name<'c, C: WithSignals /* = #class_ty */> {
242241
typed: #typed_name<'c, C>,
243242
}
244243

245-
impl<'c> #individual_struct_name<'c> {
244+
impl<'c, C: WithSignals> #individual_struct_name<'c, C> {
246245
pub fn emit(&mut self, #param_list) {
247246
self.typed.emit_tuple( (#name_list) );
248247
}

godot-core/src/registry/signal/typed_signal.rs

-7
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,6 @@ impl<'c, C: WithSignals, Ps: meta::ParamTuple> TypedSignal<'c, C, Ps> {
8484
Self::new(obj, signal_name)
8585
}
8686

87-
// pub fn extract_user<Ps: meta::ParamTuple>(
88-
// this: &mut Option<UserSignalObject<'c, C>>,
89-
// signal_name: &'static str,
90-
// ) -> TypedSignal<'c, C, Ps> {
91-
// TypedSignal::extract(this, signal_name)
92-
// }
93-
9487
// Currently only invoked from godot-core classes, or from UserSignalObject::into_typed_signal.
9588
// When making public, make also #[doc(hidden)].
9689
fn new(object: C::__SignalObj<'c>, name: &'static str) -> Self {

godot-macros/src/class/data_models/signal.rs

-6
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,7 @@ impl SignalCollection {
302302
// visibility that exceeds the class visibility). So, we can as well declare the visibility here.
303303
#vis_marker fn #signal_name(&mut self) -> #individual_struct_name<'c, C> {
304304
#individual_struct_name {
305-
// __typed: ::godot::register::TypedSignal::new(self.__internal_obj, #signal_name_str)
306-
// __typed: ::godot::register::TypedSignal::<'c, C, _>::new(self.__internal_obj, #signal_name_str)
307-
// __typed: todo!()
308-
309-
// __typed: self.__internal_obj.into_typed_signal(#signal_name_str)
310305
__typed: ::godot::register::TypedSignal::<'c, C, _>::extract(&mut self.__internal_obj, #signal_name_str)
311-
312306
}
313307
}
314308
});

itest/rust/src/builtin_tests/containers/signal_test.rs

+33
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,19 @@ fn signal_symbols_engine_inherited_indirect(ctx: &crate::framework::TestContext)
314314
node.free();
315315
}
316316

317+
// Test that Node signals are *internally* accessible from a derived class.
318+
#[cfg(since_api = "4.2")]
319+
#[itest]
320+
fn signal_symbols_engine_inherited_internal() {
321+
// No tree needed; signal is emitted manually.
322+
let mut node = Emitter::new_alloc();
323+
node.bind_mut().connect_base_signals_internal();
324+
node.bind_mut().emit_base_signals_internal();
325+
326+
assert_eq!(node.bind().last_received_int, 553);
327+
node.free();
328+
}
329+
317330
#[itest]
318331
fn signal_construction_and_id() {
319332
let mut object = RefCounted::new_gd();
@@ -375,6 +388,14 @@ mod emitter {
375388
}
376389
}
377390

391+
#[func]
392+
pub fn self_receive_constant(&mut self) {
393+
#[cfg(since_api = "4.2")]
394+
{
395+
self.last_received_int = 553;
396+
}
397+
}
398+
378399
#[func]
379400
fn self_receive_static(arg1: i64) {
380401
*LAST_STATIC_FUNCTION_ARG.lock() = arg1;
@@ -394,6 +415,18 @@ mod emitter {
394415
pub fn emit_signals_internal(&mut self) {
395416
self.signals().signal_int().emit(1234);
396417
}
418+
419+
#[cfg(since_api = "4.2")]
420+
pub fn connect_base_signals_internal(&mut self) {
421+
self.signals()
422+
.renamed()
423+
.connect_self(Self::self_receive_constant);
424+
}
425+
426+
#[cfg(since_api = "4.2")]
427+
pub fn emit_base_signals_internal(&mut self) {
428+
self.signals().renamed().emit();
429+
}
397430
}
398431
}
399432

0 commit comments

Comments
 (0)