@@ -22,7 +22,6 @@ use crate::runtime::GodotScriptObject;
22
22
godot:: sys:: plugin_registry!( pub SCRIPT_REGISTRY : RegistryItem ) ;
23
23
24
24
#[ macro_export]
25
- #[ cfg( before_api = "4.4" ) ]
26
25
macro_rules! register_script_class {
27
26
( $class_name: ty, $base_name: ty, $desc: expr, $props: expr, $signals: expr) => {
28
27
$crate:: private_export:: plugin_add! {
@@ -44,28 +43,6 @@ macro_rules! register_script_class {
44
43
} ;
45
44
}
46
45
47
- #[ macro_export]
48
- #[ cfg( since_api = "4.4" ) ]
49
- macro_rules! register_script_class {
50
- ( $class_name: ty, $base_name: ty, $desc: expr, $props: expr, $signals: expr) => {
51
- $crate:: private_export:: plugin_add! {
52
- $crate:: private_export:: SCRIPT_REGISTRY ;
53
- $crate:: private_export:: RegistryItem :: Entry ( $crate:: private_export:: RustScriptEntry {
54
- class_name: stringify!( $class_name) ,
55
- base_type_name: <$base_name as $crate:: godot:: prelude:: GodotClass >:: class_name( ) . to_cow_str( ) ,
56
- properties: || {
57
- $props
58
- } ,
59
- signals: || {
60
- $signals
61
- } ,
62
- create_data: $crate:: private_export:: create_default_data_struct:: <$class_name>,
63
- description: $desc,
64
- } )
65
- }
66
- } ;
67
- }
68
-
69
46
#[ macro_export]
70
47
macro_rules! register_script_methods {
71
48
( $class_name: ty, $methods: expr) => {
@@ -83,7 +60,6 @@ macro_rules! register_script_methods {
83
60
84
61
pub struct RustScriptEntry {
85
62
pub class_name : & ' static str ,
86
- #[ cfg( before_api = "4.4" ) ]
87
63
pub class_name_cstr : & ' static std:: ffi:: CStr ,
88
64
pub base_type_name : Cow < ' static , str > ,
89
65
pub properties : fn ( ) -> Vec < RustScriptPropDesc > ,
@@ -145,13 +121,12 @@ impl RustScriptMethodDesc {
145
121
self ,
146
122
id : i32 ,
147
123
class_name : & ' static str ,
148
- # [ cfg ( before_api = "4.4" ) ] class_name_cstr : & ' static std:: ffi:: CStr ,
124
+ class_name_cstr : & ' static std:: ffi:: CStr ,
149
125
) -> RustScriptMethodInfo {
150
126
RustScriptMethodInfo {
151
127
id,
152
128
method_name : self . name ,
153
129
class_name,
154
- #[ cfg( before_api = "4.4" ) ]
155
130
class_name_cstr,
156
131
return_type : self . return_type . to_property_info ( ) ,
157
132
flags : self . flags . ord ( ) ,
@@ -221,7 +196,6 @@ pub fn assemble_metadata<'a>(
221
196
method. into_method_info (
222
197
( index + 1 ) as i32 ,
223
198
class. class_name ,
224
- #[ cfg( before_api = "4.4" ) ]
225
199
class. class_name_cstr ,
226
200
)
227
201
} )
@@ -234,7 +208,6 @@ pub fn assemble_metadata<'a>(
234
208
235
209
RustScriptMetaData :: new (
236
210
class. class_name ,
237
- #[ cfg( before_api = "4.4" ) ]
238
211
class. class_name_cstr ,
239
212
class. base_type_name . as_ref ( ) . into ( ) ,
240
213
props,
@@ -281,7 +254,6 @@ pub struct RustScriptMethodInfo {
281
254
pub id : i32 ,
282
255
pub method_name : & ' static str ,
283
256
pub class_name : & ' static str ,
284
- #[ cfg( before_api = "4.4" ) ]
285
257
pub class_name_cstr : & ' static std:: ffi:: CStr ,
286
258
pub return_type : RustScriptPropertyInfo ,
287
259
pub arguments : Box < [ RustScriptPropertyInfo ] > ,
@@ -294,11 +266,7 @@ impl From<&RustScriptMethodInfo> for MethodInfo {
294
266
Self {
295
267
id : value. id ,
296
268
method_name : value. method_name . into ( ) ,
297
- class_name : ClassName :: new_script (
298
- value. class_name ,
299
- #[ cfg( before_api = "4.4" ) ]
300
- value. class_name_cstr ,
301
- ) ,
269
+ class_name : ClassName :: new_script ( value. class_name , value. class_name_cstr ) ,
302
270
return_type : ( & value. return_type ) . into ( ) ,
303
271
arguments : value. arguments . iter ( ) . map ( |arg| arg. into ( ) ) . collect ( ) ,
304
272
default_arguments : vec ! [ ] ,
@@ -349,10 +317,10 @@ pub struct RustScriptMetaData {
349
317
}
350
318
351
319
impl RustScriptMetaData {
352
- #[ cfg_attr ( before_api = "4.4" , expect( clippy:: too_many_arguments) ) ]
320
+ #[ expect( clippy:: too_many_arguments) ]
353
321
pub fn new (
354
322
class_name : & ' static str ,
355
- # [ cfg ( before_api = "4.4" ) ] class_name_cstr : & ' static std:: ffi:: CStr ,
323
+ class_name_cstr : & ' static std:: ffi:: CStr ,
356
324
base_type_name : StringName ,
357
325
properties : Box < [ RustScriptPropertyInfo ] > ,
358
326
methods : Box < [ RustScriptMethodInfo ] > ,
@@ -361,11 +329,8 @@ impl RustScriptMetaData {
361
329
description : & ' static str ,
362
330
) -> Self {
363
331
Self {
364
- #[ cfg( before_api = "4.4" ) ]
365
332
class_name : ClassName :: new_script ( class_name, class_name_cstr) ,
366
333
367
- #[ cfg( since_api = "4.4" ) ]
368
- class_name : ClassName :: new_script ( class_name) ,
369
334
base_type_name,
370
335
properties,
371
336
methods,
@@ -423,15 +388,10 @@ static DYNAMIC_INDEX_BY_CLASS_NAME: LazyLock<RwLock<HashMap<&'static str, ClassN
423
388
LazyLock :: new ( RwLock :: default) ;
424
389
425
390
trait ClassNameExtension {
426
- #[ cfg( before_api = "4.4" ) ]
427
391
fn new_script ( str : & ' static str , cstr : & ' static std:: ffi:: CStr ) -> Self ;
428
-
429
- #[ cfg( since_api = "4.4" ) ]
430
- fn new_script ( str : & ' static str ) -> Self ;
431
392
}
432
393
433
394
impl ClassNameExtension for ClassName {
434
- #[ cfg( before_api = "4.4" ) ]
435
395
fn new_script ( str : & ' static str , cstr : & ' static std:: ffi:: CStr ) -> Self {
436
396
// Check if class name exists.
437
397
if let Some ( name) = DYNAMIC_INDEX_BY_CLASS_NAME . read ( ) . unwrap ( ) . get ( str) {
@@ -440,27 +400,36 @@ impl ClassNameExtension for ClassName {
440
400
441
401
let mut map = DYNAMIC_INDEX_BY_CLASS_NAME . write ( ) . unwrap ( ) ;
442
402
443
- let class_name = map
444
- . entry ( str)
445
- . or_insert_with ( || ClassName :: alloc_next_ascii ( cstr) ) ;
403
+ let class_name = * map. entry ( str) . or_insert_with ( || {
404
+ if str. is_ascii ( ) {
405
+ ClassName :: alloc_next_ascii ( cstr)
406
+ } else {
407
+ ClassName :: alloc_next_unicode ( str)
408
+ }
409
+ } ) ;
446
410
447
- * class_name
411
+ class_name
448
412
}
413
+ }
449
414
450
- #[ cfg( since_api = "4.4" ) ]
451
- fn new_script ( str : & ' static str ) -> Self {
452
- // Check if class name exists.
415
+ #[ cfg( test ) ]
416
+ mod tests {
417
+ use godot :: meta :: ClassName ;
453
418
454
- if let Some ( name) = DYNAMIC_INDEX_BY_CLASS_NAME . read ( ) . unwrap ( ) . get ( str) {
455
- return * name;
456
- }
419
+ use crate :: static_script_registry:: ClassNameExtension ;
457
420
458
- let mut map = DYNAMIC_INDEX_BY_CLASS_NAME . write ( ) . unwrap ( ) ;
421
+ #[ test]
422
+ fn new_class_name ( ) {
423
+ let script_name = ClassName :: new_script ( "TestScript" , c"TestScript" ) ;
459
424
460
- let class_name = * map
461
- . entry ( str)
462
- . or_insert_with ( || ClassName :: alloc_next_unicode ( str) ) ;
425
+ assert_eq ! ( script_name. to_cow_str( ) , "TestScript" ) ;
426
+ }
463
427
464
- class_name
428
+ #[ cfg( since_api = "4.4" ) ]
429
+ #[ test]
430
+ fn new_unicode_class_name ( ) {
431
+ let script_name = ClassName :: new_script ( "ÜbertragungsScript" , c"ÜbertragungsScript" ) ;
432
+
433
+ assert_eq ! ( script_name. to_cow_str( ) , "ÜbertragungsScript" ) ;
465
434
}
466
435
}
0 commit comments