8
8
//! Parsing the `var` and `export` attributes on fields.
9
9
10
10
use crate :: class:: { Field , FieldVar , Fields , GetSet , GetterSetterImpl , UsageFlags } ;
11
- use crate :: util;
12
11
use proc_macro2:: { Ident , TokenStream } ;
13
12
use quote:: quote;
14
13
@@ -38,8 +37,6 @@ impl FieldHint {
38
37
}
39
38
40
39
pub fn make_property_impl ( class_name : & Ident , fields : & Fields ) -> TokenStream {
41
- let class_name_obj = util:: class_name_obj ( class_name) ;
42
-
43
40
let mut getter_setter_impls = Vec :: new ( ) ;
44
41
let mut export_tokens = Vec :: new ( ) ;
45
42
@@ -66,8 +63,6 @@ pub fn make_property_impl(class_name: &Ident, fields: &Fields) -> TokenStream {
66
63
continue ;
67
64
} ;
68
65
69
- let field_variant_type = util:: property_variant_type ( field_type) ;
70
- let field_class_name = util:: property_variant_class_name ( field_type) ;
71
66
let field_name = field_ident. to_string ( ) ;
72
67
73
68
let FieldVar {
@@ -104,47 +99,32 @@ pub fn make_property_impl(class_name: &Ident, fields: &Fields) -> TokenStream {
104
99
let hint = match hint {
105
100
FieldHint :: Inferred => {
106
101
if let Some ( export_hint) = export_hint {
107
- quote ! {
108
- {
109
- let :: godot:: meta:: PropertyHintInfo { hint, hint_string } = #export_hint;
110
- ( hint, hint_string)
111
- }
112
- }
102
+ quote ! { #export_hint }
113
103
} else if export. is_some ( ) {
114
- quote ! {
115
- {
116
- let export_hint = <#field_type as :: godot:: register:: property:: Export >:: export_hint( ) ;
117
- ( export_hint. hint, export_hint. hint_string)
118
- }
119
- }
104
+ quote ! { <#field_type as :: godot:: register:: property:: Export >:: export_hint( ) }
120
105
} else {
121
- quote ! {
122
- {
123
- let export_hint = <#field_type as :: godot:: register:: property:: Var >:: var_hint( ) ;
124
- ( export_hint. hint, export_hint. hint_string)
125
- }
126
- }
106
+ quote ! { <#field_type as :: godot:: register:: property:: Var >:: var_hint( ) }
127
107
}
128
108
}
129
109
FieldHint :: Hint ( hint) => {
130
110
let hint_string = if let Some ( export_hint) = export_hint {
131
111
quote ! { #export_hint. hint_string }
132
112
} else {
133
- quote ! { : godot:: builtin:: GString :: new( ) }
113
+ quote ! { :: godot:: builtin:: GString :: new( ) }
134
114
} ;
135
115
136
116
quote ! {
137
- (
138
- :: godot:: global:: PropertyHint :: #hint,
139
- #hint_string
140
- )
117
+ :: godot :: meta :: PropertyHintInfo {
118
+ hint : :: godot:: global:: PropertyHint :: #hint,
119
+ hint_string : #hint_string,
120
+ }
141
121
}
142
122
}
143
123
FieldHint :: HintWithString { hint, hint_string } => quote ! {
144
- (
145
- :: godot:: global:: PropertyHint :: #hint,
146
- :: godot:: builtin:: GString :: from( #hint_string)
147
- )
124
+ :: godot :: meta :: PropertyHintInfo {
125
+ hint : :: godot:: global:: PropertyHint :: #hint,
126
+ hint_string : :: godot:: builtin:: GString :: from( #hint_string) ,
127
+ }
148
128
} ,
149
129
} ;
150
130
@@ -160,36 +140,13 @@ pub fn make_property_impl(class_name: &Ident, fields: &Fields) -> TokenStream {
160
140
) ;
161
141
162
142
export_tokens. push ( quote ! {
163
- use :: godot:: sys:: GodotFfi ;
164
-
165
- let ( hint, hint_string) = #hint;
166
- let usage = #usage_flags;
167
-
168
- let property_info = :: godot:: meta:: PropertyInfo {
169
- variant_type: #field_variant_type,
170
- class_name: #field_class_name,
171
- property_name: #field_name. into( ) ,
172
- hint_info: :: godot:: meta:: PropertyHintInfo {
173
- hint,
174
- hint_string,
175
- } ,
176
- usage,
177
- } ;
178
-
179
- let getter_name = :: godot:: builtin:: StringName :: from( #getter_name) ;
180
- let setter_name = :: godot:: builtin:: StringName :: from( #setter_name) ;
181
-
182
- let property_info_sys = property_info. property_sys( ) ;
183
-
184
- unsafe {
185
- :: godot:: sys:: interface_fn!( classdb_register_extension_class_property) (
186
- :: godot:: sys:: get_library( ) ,
187
- #class_name_obj. string_sys( ) ,
188
- std:: ptr:: addr_of!( property_info_sys) ,
189
- setter_name. string_sys( ) ,
190
- getter_name. string_sys( ) ,
191
- ) ;
192
- }
143
+ :: godot:: register:: private:: register_var_or_export:: <#class_name, #field_type>(
144
+ #field_name,
145
+ #getter_name,
146
+ #setter_name,
147
+ #hint,
148
+ #usage_flags,
149
+ ) ;
193
150
} ) ;
194
151
}
195
152
0 commit comments