6
6
7
7
use std:: collections:: BTreeMap ;
8
8
9
- use abi_stable:: {
10
- sabi_trait:: TD_Opaque ,
11
- std_types:: { RBox , RStr , RString , RVec } ,
12
- } ;
13
9
use godot:: {
14
10
engine:: global:: { MethodFlags , PropertyHint , PropertyUsageFlags } ,
15
11
obj:: { EngineBitfield , EngineEnum } ,
16
12
prelude:: { Gd , Object } ,
17
13
sys:: VariantType ,
18
14
} ;
19
15
20
- pub use crate :: script_registry:: {
21
- GodotScript , GodotScriptImpl , RemoteScriptMetaData , RemoteScriptMethodInfo ,
16
+ use crate :: script_registry:: {
17
+ CreateScriptInstanceData , GodotScriptObject , RustScriptPropertyInfo , RustScriptSignalInfo ,
22
18
} ;
23
- use crate :: {
24
- apply:: Apply ,
25
- script_registry:: { RemoteGodotScript_TO , RemoteScriptPropertyInfo , RemoteScriptSignalInfo } ,
19
+ pub use crate :: script_registry:: {
20
+ GodotScript , GodotScriptImpl , RustScriptMetaData , RustScriptMethodInfo ,
26
21
} ;
27
22
pub use signals:: { ScriptSignal , Signal , SignalArguments } ;
28
23
@@ -68,8 +63,7 @@ macro_rules! register_script_methods {
68
63
macro_rules! setup_library {
69
64
( ) => {
70
65
#[ no_mangle]
71
- pub fn __godot_rust_script_init(
72
- ) -> $crate:: private_export:: RVec <$crate:: RemoteScriptMetaData > {
66
+ pub fn __godot_rust_script_init( ) -> :: std:: vec:: Vec <$crate:: RustScriptMetaData > {
73
67
use $crate:: godot:: obj:: EngineEnum ;
74
68
use $crate:: private_export:: * ;
75
69
@@ -100,7 +94,7 @@ pub struct RustScriptEntry {
100
94
pub base_type_name : & ' static str ,
101
95
pub properties : fn ( ) -> Vec < RustScriptPropDesc > ,
102
96
pub signals : fn ( ) -> Vec < RustScriptSignalDesc > ,
103
- pub create_data : fn ( Gd < Object > ) -> RemoteGodotScript_TO < ' static , RBox < ( ) > > ,
97
+ pub create_data : fn ( Gd < Object > ) -> Box < dyn GodotScriptObject > ,
104
98
pub description : & ' static str ,
105
99
}
106
100
@@ -126,78 +120,78 @@ pub struct RustScriptPropDesc {
126
120
}
127
121
128
122
impl RustScriptPropDesc {
129
- pub fn into_property_info ( self , class_name : & ' static str ) -> RemoteScriptPropertyInfo {
130
- RemoteScriptPropertyInfo {
131
- variant_type : self . ty . into ( ) ,
132
- class_name : RStr :: from_str ( class_name ) ,
133
- property_name : RString :: with_capacity ( self . name . len ( ) ) . apply ( |s| s . push_str ( self . name ) ) ,
123
+ pub fn to_property_info ( & self , class_name : & ' static str ) -> RustScriptPropertyInfo {
124
+ RustScriptPropertyInfo {
125
+ variant_type : self . ty ,
126
+ class_name,
127
+ property_name : self . name ,
134
128
usage : if self . exported {
135
129
( PropertyUsageFlags :: EDITOR | PropertyUsageFlags :: STORAGE ) . ord ( )
136
130
} else {
137
131
PropertyUsageFlags :: NONE . ord ( )
138
132
} ,
139
133
hint : self . hint . ord ( ) ,
140
- hint_string : self . hint_string . into ( ) ,
141
- description : RStr :: from_str ( self . description ) ,
134
+ hint_string : self . hint_string ,
135
+ description : self . description ,
142
136
}
143
137
}
144
138
}
145
139
146
140
pub struct RustScriptMethodDesc {
147
141
pub name : & ' static str ,
148
142
pub return_type : RustScriptPropDesc ,
149
- pub arguments : Vec < RustScriptPropDesc > ,
143
+ pub arguments : Box < [ RustScriptPropDesc ] > ,
150
144
pub flags : MethodFlags ,
151
145
pub description : & ' static str ,
152
146
}
153
147
154
148
impl RustScriptMethodDesc {
155
- pub fn into_method_info ( self , id : i32 , class_name : & ' static str ) -> RemoteScriptMethodInfo {
156
- RemoteScriptMethodInfo {
149
+ pub fn to_method_info ( self , id : i32 , class_name : & ' static str ) -> RustScriptMethodInfo {
150
+ RustScriptMethodInfo {
157
151
id,
158
- method_name : self . name . into ( ) ,
159
- class_name : class_name . into ( ) ,
160
- return_type : self . return_type . into_property_info ( class_name) ,
152
+ method_name : self . name ,
153
+ class_name,
154
+ return_type : self . return_type . to_property_info ( class_name) ,
161
155
flags : self . flags . ord ( ) ,
162
156
arguments : self
163
157
. arguments
164
- . into_iter ( )
165
- . map ( |arg| arg. into_property_info ( class_name) )
158
+ . iter ( )
159
+ . map ( |arg| arg. to_property_info ( class_name) )
166
160
. collect ( ) ,
167
- description : RStr :: from_str ( self . description ) ,
161
+ description : self . description ,
168
162
}
169
163
}
170
164
}
171
165
172
166
pub struct RustScriptSignalDesc {
173
167
pub name : & ' static str ,
174
- pub arguments : Vec < RustScriptPropDesc > ,
168
+ pub arguments : Box < [ RustScriptPropDesc ] > ,
175
169
pub description : & ' static str ,
176
170
}
177
171
178
- impl From < RustScriptSignalDesc > for RemoteScriptSignalInfo {
172
+ impl From < RustScriptSignalDesc > for RustScriptSignalInfo {
179
173
fn from ( value : RustScriptSignalDesc ) -> Self {
180
174
Self {
181
- name : value. name . into ( ) ,
175
+ name : value. name ,
182
176
arguments : value
183
177
. arguments
184
- . into_iter ( )
185
- . map ( |arg| arg. into_property_info ( "\0 " ) )
178
+ . iter ( )
179
+ . map ( |arg| arg. to_property_info ( "\0 " ) )
186
180
. collect ( ) ,
187
- description : value. description . into ( ) ,
181
+ description : value. description ,
188
182
}
189
183
}
190
184
}
191
185
192
- pub fn create_default_data_struct < T : GodotScript + ' static > (
186
+ pub fn create_default_data_struct < T : GodotScript + GodotScriptObject + ' static > (
193
187
base : Gd < Object > ,
194
- ) -> RemoteGodotScript_TO < ' static , RBox < ( ) > > {
195
- RemoteGodotScript_TO :: from_value ( T :: default_with_base ( base) , TD_Opaque )
188
+ ) -> Box < dyn GodotScriptObject > {
189
+ Box :: new ( T :: default_with_base ( base) )
196
190
}
197
191
198
192
pub fn assemble_metadata < ' a > (
199
193
items : impl Iterator < Item = & ' a RegistryItem > + ' a ,
200
- ) -> RVec < RemoteScriptMetaData > {
194
+ ) -> Vec < RustScriptMetaData > {
201
195
let ( entries, methods) : ( Vec < _ > , Vec < _ > ) = items
202
196
. map ( |item| match item {
203
197
RegistryItem :: Entry ( entry) => ( Some ( entry) , None ) ,
@@ -213,32 +207,30 @@ pub fn assemble_metadata<'a>(
213
207
. map ( |class| {
214
208
let props = ( class. properties ) ( )
215
209
. into_iter ( )
216
- . map ( |prop| prop. into_property_info ( class. class_name ) )
210
+ . map ( |prop| prop. to_property_info ( class. class_name ) )
217
211
. collect ( ) ;
218
212
219
213
let methods = methods
220
214
. get ( class. class_name )
221
215
. into_iter ( )
222
216
. flat_map ( |entry| ( entry. methods ) ( ) )
223
217
. enumerate ( )
224
- . map ( |( index, method) | {
225
- method. into_method_info ( ( index + 1 ) as i32 , class. class_name )
226
- } )
218
+ . map ( |( index, method) | method. to_method_info ( ( index + 1 ) as i32 , class. class_name ) )
227
219
. collect ( ) ;
228
220
229
221
let signals = ( class. signals ) ( ) . into_iter ( ) . map ( Into :: into) . collect ( ) ;
230
222
231
- let create_data = class. create_data ;
223
+ let create_data: Box < dyn CreateScriptInstanceData > = Box :: new ( class. create_data ) ;
232
224
let description = class. description ;
233
225
234
- RemoteScriptMetaData :: new (
235
- class. class_name . into ( ) ,
226
+ RustScriptMetaData :: new (
227
+ class. class_name ,
236
228
class. base_type_name . into ( ) ,
237
229
props,
238
230
methods,
239
231
signals,
240
232
create_data,
241
- description. into ( ) ,
233
+ description,
242
234
)
243
235
} )
244
236
. collect ( )
0 commit comments