4
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
5
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
6
*/
7
+
7
8
use crate :: class:: {
8
9
into_signature_info, make_constant_registration, make_method_registration,
9
10
make_signal_registrations, ConstDefinition , FuncDefinition , RpcAttr , RpcMode , SignalDefinition ,
@@ -66,7 +67,7 @@ struct FuncAttr {
66
67
67
68
pub struct InherentImplAttr {
68
69
/// For implementation reasons, there can be a single 'primary' impl block and 0 or more 'secondary' impl blocks.
69
- /// For now this is controlled by a key in the the 'godot_api' attribute
70
+ /// For now, this is controlled by a key in the 'godot_api' attribute.
70
71
pub secondary : bool ,
71
72
}
72
73
@@ -80,7 +81,7 @@ pub fn transform_inherent_impl(
80
81
let prv = quote ! { :: godot:: private } ;
81
82
82
83
// Can add extra functions to the end of the impl block.
83
- let ( funcs, signals) = process_godot_fns ( & class_name, & mut impl_block) ?;
84
+ let ( funcs, signals) = process_godot_fns ( & class_name, & mut impl_block, meta . secondary ) ?;
84
85
let consts = process_godot_constants ( & mut impl_block) ?;
85
86
86
87
#[ cfg( all( feature = "register-docs" , since_api = "4.3" ) ) ]
@@ -107,16 +108,13 @@ pub fn transform_inherent_impl(
107
108
108
109
let fill_storage = quote ! {
109
110
:: godot:: sys:: plugin_execute_pre_main!( {
110
- #method_storage_name. lock( ) . unwrap( ) . push( ||{
111
-
111
+ #method_storage_name. lock( ) . unwrap( ) . push( || {
112
112
#( #method_registrations ) *
113
113
#( #signal_registrations ) *
114
-
115
114
} ) ;
116
- #constants_storage_name. lock( ) . unwrap( ) . push( ||{
117
115
116
+ #constants_storage_name. lock( ) . unwrap( ) . push( || {
118
117
#constant_registration
119
-
120
118
} ) ;
121
119
} ) ;
122
120
} ;
@@ -155,7 +153,6 @@ pub fn transform_inherent_impl(
155
153
} ;
156
154
157
155
let class_registration = quote ! {
158
-
159
156
:: godot:: sys:: plugin_add!( __GODOT_PLUGIN_REGISTRY in #prv; #prv:: ClassPlugin {
160
157
class_name: #class_name_obj,
161
158
item: #prv:: PluginItem :: InherentImpl ( #prv:: InherentImpl {
@@ -169,7 +166,6 @@ pub fn transform_inherent_impl(
169
166
} ) ,
170
167
init_level: <#class_name as :: godot:: obj:: GodotClass >:: INIT_LEVEL ,
171
168
} ) ;
172
-
173
169
} ;
174
170
175
171
let result = quote ! {
@@ -182,7 +178,7 @@ pub fn transform_inherent_impl(
182
178
183
179
Ok ( result)
184
180
} else {
185
- // We are in a secondary `impl` block, so most of the work has already been done
181
+ // We are in a secondary `impl` block, so most of the work has already been done,
186
182
// and we just need to add our registration functions in the storage defined by the primary `impl` block.
187
183
188
184
let result = quote ! {
@@ -197,6 +193,7 @@ pub fn transform_inherent_impl(
197
193
fn process_godot_fns (
198
194
class_name : & Ident ,
199
195
impl_block : & mut venial:: Impl ,
196
+ is_secondary_impl : bool ,
200
197
) -> ParseResult < ( Vec < FuncDefinition > , Vec < SignalDefinition > ) > {
201
198
let mut func_definitions = vec ! [ ] ;
202
199
let mut signal_definitions = vec ! [ ] ;
@@ -286,9 +283,16 @@ fn process_godot_fns(
286
283
rpc_info,
287
284
} ) ;
288
285
}
286
+
289
287
ItemAttrType :: Signal ( ref _attr_val) => {
288
+ if is_secondary_impl {
289
+ return attr. bail (
290
+ "#[signal] is not currently supported in secondary impl blocks" ,
291
+ function,
292
+ ) ;
293
+ }
290
294
if function. return_ty . is_some ( ) {
291
- return attr. bail ( "return types are not supported" , function) ;
295
+ return attr. bail ( "return types in #[signal] are not supported" , function) ;
292
296
}
293
297
294
298
let external_attributes = function. attributes . clone ( ) ;
@@ -301,6 +305,7 @@ fn process_godot_fns(
301
305
302
306
removed_indexes. push ( index) ;
303
307
}
308
+
304
309
ItemAttrType :: Const ( _) => {
305
310
return attr. bail (
306
311
"#[constant] can only be used on associated constant" ,
@@ -541,12 +546,7 @@ where
541
546
}
542
547
543
548
// #[signal]
544
- name if name == "signal" => {
545
- // TODO once parameters are supported, this should probably be moved to the struct definition
546
- // E.g. a zero-sized type Signal<(i32, String)> with a provided emit(i32, String) method
547
- // This could even be made public (callable on the struct obj itself)
548
- AttrParseResult :: Signal ( attr. value . clone ( ) )
549
- }
549
+ name if name == "signal" => AttrParseResult :: Signal ( attr. value . clone ( ) ) ,
550
550
551
551
// #[constant]
552
552
name if name == "constant" => AttrParseResult :: Const ( attr. value . clone ( ) ) ,
0 commit comments