@@ -270,3 +270,65 @@ 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+ ///
290+ /// The struct returned by this function contains pointers into the fields of `self`. `self` should therefore not be dropped while the
291+ /// [`sys::GDExtensionMethodInfo`] is still in use.
292+ ///
293+ /// This function also leaks memory that has to be cleaned up by the caller once it is no longer used. Specifically the `arguments` and
294+ /// `default_arguments` vectors have to be reconstruced from the pointer and length and then dropped / freed.
295+ ///
296+ /// Each vector can be reconstructed with `Vec::from_raw_parts` since the pointers where created with `Vec::into_boxed_slice` which
297+ /// gurantees that vector capacity and length are equal.
298+ pub fn method_sys ( & self ) -> sys:: GDExtensionMethodInfo {
299+ use crate :: obj:: EngineEnum as _;
300+
301+ let argument_count = self . arguments . len ( ) as u32 ;
302+ let argument_vec = self
303+ . arguments
304+ . iter ( )
305+ . map ( |arg| arg. property_sys ( ) )
306+ . collect :: < Vec < _ > > ( )
307+ . into_boxed_slice ( ) ;
308+
309+ // SAFETY: dereferencing the new box pointer is fine as it is guaranteed to not be null
310+ let arguments = unsafe { ( * Box :: into_raw ( argument_vec) ) . as_mut_ptr ( ) } ;
311+
312+ let default_argument_count = self . default_arguments . len ( ) as u32 ;
313+ let default_argument_vec = self
314+ . default_arguments
315+ . iter ( )
316+ . map ( |arg| arg. var_sys ( ) )
317+ . collect :: < Vec < _ > > ( )
318+ . into_boxed_slice ( ) ;
319+
320+ // SAFETY: dereferencing the new box pointer is fine as it is guaranteed to not be null
321+ let default_arguments = unsafe { ( * Box :: into_raw ( default_argument_vec) ) . as_mut_ptr ( ) } ;
322+
323+ sys:: GDExtensionMethodInfo {
324+ id : self . id ,
325+ name : self . method_name . string_sys ( ) ,
326+ return_value : self . return_type . property_sys ( ) ,
327+ argument_count,
328+ arguments,
329+ default_argument_count,
330+ default_arguments,
331+ flags : u32:: try_from ( self . flags . ord ( ) ) . expect ( "flags should be valid" ) ,
332+ }
333+ }
334+ }
0 commit comments