66
77use std:: collections:: BTreeMap ;
88
9- use abi_stable:: {
10- sabi_trait:: TD_Opaque ,
11- std_types:: { RBox , RStr , RString , RVec } ,
12- } ;
139use godot:: {
1410 engine:: global:: { MethodFlags , PropertyHint , PropertyUsageFlags } ,
1511 obj:: { EngineBitfield , EngineEnum } ,
1612 prelude:: { Gd , Object } ,
1713 sys:: VariantType ,
1814} ;
1915
20- pub use crate :: script_registry:: {
21- GodotScript , GodotScriptImpl , RemoteScriptMetaData , RemoteScriptMethodInfo ,
16+ use crate :: script_registry:: {
17+ CreateScriptInstanceData , GodotScriptObject , RustScriptPropertyInfo , RustScriptSignalInfo ,
2218} ;
23- use crate :: {
24- apply:: Apply ,
25- script_registry:: { RemoteGodotScript_TO , RemoteScriptPropertyInfo , RemoteScriptSignalInfo } ,
19+ pub use crate :: script_registry:: {
20+ GodotScript , GodotScriptImpl , RustScriptMetaData , RustScriptMethodInfo ,
2621} ;
2722pub use signals:: { ScriptSignal , Signal , SignalArguments } ;
2823
@@ -68,8 +63,7 @@ macro_rules! register_script_methods {
6863macro_rules! setup_library {
6964 ( ) => {
7065 #[ 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 > {
7367 use $crate:: godot:: obj:: EngineEnum ;
7468 use $crate:: private_export:: * ;
7569
@@ -100,7 +94,7 @@ pub struct RustScriptEntry {
10094 pub base_type_name : & ' static str ,
10195 pub properties : fn ( ) -> Vec < RustScriptPropDesc > ,
10296 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 > ,
10498 pub description : & ' static str ,
10599}
106100
@@ -126,78 +120,78 @@ pub struct RustScriptPropDesc {
126120}
127121
128122impl 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 ,
134128 usage : if self . exported {
135129 ( PropertyUsageFlags :: EDITOR | PropertyUsageFlags :: STORAGE ) . ord ( )
136130 } else {
137131 PropertyUsageFlags :: NONE . ord ( )
138132 } ,
139133 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 ,
142136 }
143137 }
144138}
145139
146140pub struct RustScriptMethodDesc {
147141 pub name : & ' static str ,
148142 pub return_type : RustScriptPropDesc ,
149- pub arguments : Vec < RustScriptPropDesc > ,
143+ pub arguments : Box < [ RustScriptPropDesc ] > ,
150144 pub flags : MethodFlags ,
151145 pub description : & ' static str ,
152146}
153147
154148impl 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 {
157151 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) ,
161155 flags : self . flags . ord ( ) ,
162156 arguments : self
163157 . arguments
164- . into_iter ( )
165- . map ( |arg| arg. into_property_info ( class_name) )
158+ . iter ( )
159+ . map ( |arg| arg. to_property_info ( class_name) )
166160 . collect ( ) ,
167- description : RStr :: from_str ( self . description ) ,
161+ description : self . description ,
168162 }
169163 }
170164}
171165
172166pub struct RustScriptSignalDesc {
173167 pub name : & ' static str ,
174- pub arguments : Vec < RustScriptPropDesc > ,
168+ pub arguments : Box < [ RustScriptPropDesc ] > ,
175169 pub description : & ' static str ,
176170}
177171
178- impl From < RustScriptSignalDesc > for RemoteScriptSignalInfo {
172+ impl From < RustScriptSignalDesc > for RustScriptSignalInfo {
179173 fn from ( value : RustScriptSignalDesc ) -> Self {
180174 Self {
181- name : value. name . into ( ) ,
175+ name : value. name ,
182176 arguments : value
183177 . arguments
184- . into_iter ( )
185- . map ( |arg| arg. into_property_info ( "\0 " ) )
178+ . iter ( )
179+ . map ( |arg| arg. to_property_info ( "\0 " ) )
186180 . collect ( ) ,
187- description : value. description . into ( ) ,
181+ description : value. description ,
188182 }
189183 }
190184}
191185
192- pub fn create_default_data_struct < T : GodotScript + ' static > (
186+ pub fn create_default_data_struct < T : GodotScript + GodotScriptObject + ' static > (
193187 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) )
196190}
197191
198192pub fn assemble_metadata < ' a > (
199193 items : impl Iterator < Item = & ' a RegistryItem > + ' a ,
200- ) -> RVec < RemoteScriptMetaData > {
194+ ) -> Vec < RustScriptMetaData > {
201195 let ( entries, methods) : ( Vec < _ > , Vec < _ > ) = items
202196 . map ( |item| match item {
203197 RegistryItem :: Entry ( entry) => ( Some ( entry) , None ) ,
@@ -213,32 +207,30 @@ pub fn assemble_metadata<'a>(
213207 . map ( |class| {
214208 let props = ( class. properties ) ( )
215209 . into_iter ( )
216- . map ( |prop| prop. into_property_info ( class. class_name ) )
210+ . map ( |prop| prop. to_property_info ( class. class_name ) )
217211 . collect ( ) ;
218212
219213 let methods = methods
220214 . get ( class. class_name )
221215 . into_iter ( )
222216 . flat_map ( |entry| ( entry. methods ) ( ) )
223217 . 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 ) )
227219 . collect ( ) ;
228220
229221 let signals = ( class. signals ) ( ) . into_iter ( ) . map ( Into :: into) . collect ( ) ;
230222
231- let create_data = class. create_data ;
223+ let create_data: Box < dyn CreateScriptInstanceData > = Box :: new ( class. create_data ) ;
232224 let description = class. description ;
233225
234- RemoteScriptMetaData :: new (
235- class. class_name . into ( ) ,
226+ RustScriptMetaData :: new (
227+ class. class_name ,
236228 class. base_type_name . into ( ) ,
237229 props,
238230 methods,
239231 signals,
240232 create_data,
241- description. into ( ) ,
233+ description,
242234 )
243235 } )
244236 . collect ( )
0 commit comments