@@ -460,18 +460,27 @@ macro_rules! impl_pointer_convert {
460460 type Via = i64 ;
461461 }
462462
463- impl ToGodot for $Ptr {
463+ // Pointers implement internal-only conversion traits for use in engine APIs and virtual methods.
464+ impl meta:: EngineToGodot for $Ptr {
464465 type Pass = meta:: ByValue ;
465466
466- fn to_godot ( & self ) -> Self :: Via {
467+ fn engine_to_godot ( & self ) -> meta :: ToArg < ' _ , Self :: Via , Self :: Pass > {
467468 * self as i64
468469 }
470+
471+ fn engine_to_variant( & self ) -> Variant {
472+ Variant :: from( * self as i64 )
473+ }
469474 }
470475
471- impl FromGodot for $Ptr {
472- fn try_from_godot ( via: Self :: Via ) -> Result <Self , ConvertError > {
476+ impl meta :: EngineFromGodot for $Ptr {
477+ fn engine_try_from_godot ( via: Self :: Via ) -> Result <Self , ConvertError > {
473478 Ok ( via as Self )
474479 }
480+
481+ fn engine_try_from_variant( variant: & Variant ) -> Result <Self , ConvertError > {
482+ variant. try_to:: <i64 >( ) . map( |i| i as Self )
483+ }
475484 }
476485 } ;
477486}
@@ -480,10 +489,85 @@ impl_pointer_convert!(*const std::ffi::c_void);
480489impl_pointer_convert ! ( * mut std:: ffi:: c_void) ;
481490
482491// Some other pointer types are used by various other methods, see https://github.com/godot-rust/gdext/issues/677
483- // TODO: Find better solution to this, this may easily break still if godot decides to add more pointer arguments .
492+ // Keep manually extending this; no point in automating with how rarely Godot adds new pointer types .
484493
485494impl_pointer_convert ! ( * mut * const u8 ) ;
486495impl_pointer_convert ! ( * mut i32 ) ;
487496impl_pointer_convert ! ( * mut f64 ) ;
488497impl_pointer_convert ! ( * mut u8 ) ;
489498impl_pointer_convert ! ( * const u8 ) ;
499+
500+ // ----------------------------------------------------------------------------------------------------------------------------------------------
501+ // Tests for ToGodot/FromGodot missing impls
502+ //
503+ // Sanity check: comment-out ::godot::meta::ensure_func_bounds in func.rs, the 3 latter #[func] ones should fail.
504+
505+ /// Test that `*mut i32` cannot be converted to variant.
506+ ///
507+ /// ```compile_fail
508+ /// # use godot::prelude::*;
509+ /// let ptr: *mut i32 = std::ptr::null_mut();
510+ /// let variant = ptr.to_variant(); // Error: *mut i32 does not implement ToGodot
511+ /// ```
512+ fn __doctest_i32_ptr_to_variant ( ) { }
513+
514+ /// Test that void-pointers cannot be converted from variant.
515+ ///
516+ /// ```compile_fail
517+ /// # use godot::prelude::*;
518+ /// let variant = Variant::nil();
519+ /// let ptr: *const std::ffi::c_void = variant.to();
520+ /// ```
521+ fn __doctest_void_ptr_from_variant ( ) { }
522+
523+ /// Test that native struct pointers cannot be used as `#[func]` parameters.
524+ ///
525+ /// ```compile_fail
526+ /// # use godot::prelude::*;
527+ /// # use godot::classes::native::AudioFrame;
528+ /// #[derive(GodotClass)]
529+ /// #[class(init)]
530+ /// struct MyClass {}
531+ ///
532+ /// #[godot_api]
533+ /// impl MyClass {
534+ /// #[func]
535+ /// fn take_pointer(&self, ptr: *mut AudioFrame) {}
536+ /// }
537+ /// ```
538+ fn __doctest_native_struct_pointer_param ( ) { }
539+
540+ /// Test that native struct pointers cannot be used as `#[func]` return types.
541+ ///
542+ /// ```compile_fail
543+ /// # use godot::prelude::*;
544+ /// # use godot::classes::native::AudioFrame;
545+ /// #[derive(GodotClass)]
546+ /// #[class(init)]
547+ /// struct MyClass {}
548+ ///
549+ /// #[godot_api]
550+ /// impl MyClass {
551+ /// #[func]
552+ /// fn return_pointer(&self) -> *const AudioFrame {
553+ /// std::ptr::null()
554+ /// }
555+ /// }
556+ /// ```
557+ fn __doctest_native_struct_pointer_return ( ) { }
558+
559+ /// Test that `u64` cannot be returned from `#[func]`.
560+ ///
561+ /// ```compile_fail
562+ /// # use godot::prelude::*;
563+ /// #[derive(GodotClass)]
564+ /// #[class(init)]
565+ /// struct MyClass {}
566+ ///
567+ /// #[godot_api]
568+ /// impl MyClass {
569+ /// #[func]
570+ /// fn return_pointer(&self) -> u64 { 123 }
571+ /// }
572+ /// ```
573+ fn __doctest_u64_return ( ) { }
0 commit comments