@@ -270,3 +270,64 @@ impl PropertyInfo {
270270 }
271271 }
272272}
273+
274+ #[ derive( Debug ) ]
275+ pub struct MethodInfo {
276+ pub id : i32 ,
277+ pub method_name : StringName ,
278+ pub class_name : ClassName ,
279+ pub return_type : PropertyInfo ,
280+ pub arguments : Vec < PropertyInfo > ,
281+ pub default_arguments : Vec < Variant > ,
282+ pub flags : global:: MethodFlags ,
283+ }
284+
285+ impl MethodInfo {
286+ /// Converts to the FFI type. Keep this object allocated while using that!
287+ ///
288+ /// # Safety
289+ /// This function leaks memory that has to be cleaned up by the caller
290+ /// once it is no longer used. Specifically the `arguments` and
291+ /// `default_arguments` vectors have to be reconstruced from the pointer
292+ /// and length and then dropped / freed.
293+ ///
294+ /// Each vector can be reconstructed with `Vec::from_raw_parts` since the
295+ /// pointers where created with `Vec::into_boxed_slice` which gurantees that
296+ /// vector capacity and length are equal.
297+ pub fn method_sys ( & self ) -> sys:: GDExtensionMethodInfo {
298+ use crate :: obj:: EngineEnum as _;
299+
300+ let argument_count = self . arguments . len ( ) as u32 ;
301+ let argument_vec = self
302+ . arguments
303+ . iter ( )
304+ . map ( |arg| arg. property_sys ( ) )
305+ . collect :: < Vec < _ > > ( )
306+ . into_boxed_slice ( ) ;
307+
308+ // SAFETY: dereferencing the new box pointer is fine as it is guaranteed to not be null
309+ let arguments = unsafe { ( * Box :: into_raw ( argument_vec) ) . as_mut_ptr ( ) } ;
310+
311+ let default_argument_count = self . default_arguments . len ( ) as u32 ;
312+ let default_argument_vec = self
313+ . default_arguments
314+ . iter ( )
315+ . map ( |arg| arg. var_sys ( ) )
316+ . collect :: < Vec < _ > > ( )
317+ . into_boxed_slice ( ) ;
318+
319+ // SAFETY: dereferencing the new box pointer is fine as it is guaranteed to not be null
320+ let default_arguments = unsafe { ( * Box :: into_raw ( default_argument_vec) ) . as_mut_ptr ( ) } ;
321+
322+ sys:: GDExtensionMethodInfo {
323+ id : self . id ,
324+ name : self . method_name . string_sys ( ) ,
325+ return_value : self . return_type . property_sys ( ) ,
326+ argument_count,
327+ arguments,
328+ default_argument_count,
329+ default_arguments,
330+ flags : u32:: try_from ( self . flags . ord ( ) ) . expect ( "flags should be valid" ) ,
331+ }
332+ }
333+ }
0 commit comments