diff --git a/godot-core/src/builtin/array.rs b/godot-core/src/builtin/array.rs index 08c0bcf34..dbf601cfa 100644 --- a/godot-core/src/builtin/array.rs +++ b/godot-core/src/builtin/array.rs @@ -28,7 +28,7 @@ use super::meta::{FromGodot, GodotConvert, GodotFfiVariant, GodotType, ToGodot}; /// /// Godot also supports typed arrays, which are also just `Variant` arrays under the hood, but with /// runtime checks that no values of the wrong type are put into the array. We represent this as -/// `Array`, where the type `T` implements `VariantMetadata`, `FromGodot` and `ToGodot`. +/// `Array`, where the type `T` implements `GodotType`. /// /// # Reference semantics /// @@ -47,10 +47,10 @@ use super::meta::{FromGodot, GodotConvert, GodotFfiVariant, GodotType, ToGodot}; /// concurrent modification on other threads (e.g. created through GDScript). -// `T` must be restricted to `VariantMetadata` in the type, because `Drop` can only be implemented +// `T` must be restricted to `GodotType` in the type, because `Drop` can only be implemented // for `T: GodotType` because `drop()` requires `sys_mut()`, which is on the `GodotFfi` // trait, whose `from_sys_init()` requires `Default`, which is only implemented for `T: -// VariantMetadata`. Whew. This could be fixed by splitting up `GodotFfi` if desired. +// GodotType`. Whew. This could be fixed by splitting up `GodotFfi` if desired. #[repr(C)] pub struct Array { opaque: sys::types::OpaqueArray, diff --git a/godot-core/src/builtin/meta/mod.rs b/godot-core/src/builtin/meta/mod.rs index a72284f4e..27ee1035d 100644 --- a/godot-core/src/builtin/meta/mod.rs +++ b/godot-core/src/builtin/meta/mod.rs @@ -126,6 +126,7 @@ pub trait GodotType: GodotConvert + ToGodot + FromGodot + sealed::Se } fn class_name() -> ClassName { + println!("class_name default impl"); // If we use `ClassName::of::<()>()` then this type shows up as `(no base)` in documentation. ClassName::none() } @@ -184,6 +185,26 @@ where Some(GodotType::from_ffi(ffi)) } + + fn param_metadata() -> sys::GDExtensionClassMethodArgumentMetadata { + T::param_metadata() + } + + fn class_name() -> ClassName { + T::class_name() + } + + fn property_info(property_name: &str) -> PropertyInfo { + T::property_info(property_name) + } + + fn argument_info(property_name: &str) -> MethodParamOrReturnInfo { + T::argument_info(property_name) + } + + fn return_info() -> Option { + T::return_info() + } } // ---------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/godot-core/src/obj/gd.rs b/godot-core/src/obj/gd.rs index be78d361e..41802b31e 100644 --- a/godot-core/src/obj/gd.rs +++ b/godot-core/src/obj/gd.rs @@ -459,6 +459,11 @@ impl GodotType for Gd { Some(Self { raw }) } } + + fn class_name() -> crate::builtin::meta::ClassName { + println!("class_name gd"); + T::class_name() + } } impl Clone for Gd { @@ -540,13 +545,13 @@ impl Eq for Gd {} impl Display for Gd { fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { - engine::display_string(&self, f) + engine::display_string(self, f) } } impl Debug for Gd { fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { - engine::debug_string(&self, f, "Gd") + engine::debug_string(self, f, "Gd") } } diff --git a/godot-core/src/obj/raw.rs b/godot-core/src/obj/raw.rs index f7a369624..ac10cbb06 100644 --- a/godot-core/src/obj/raw.rs +++ b/godot-core/src/obj/raw.rs @@ -514,6 +514,8 @@ impl GodotType for RawGd { } fn class_name() -> ClassName { + println!("class_name gd"); + T::class_name() } } diff --git a/godot-macros/src/lib.rs b/godot-macros/src/lib.rs index 4e44271cc..69f6362da 100644 --- a/godot-macros/src/lib.rs +++ b/godot-macros/src/lib.rs @@ -474,7 +474,7 @@ pub fn derive_godot_compatible(input: TokenStream) -> TokenStream { /// assert_eq!(obj.to_variant(), dict.to_variant()); /// ``` /// -/// You can use the `#[skip]` attribute to ignore a field from being converted to `ToVariant`. +/// You can use the `#[skip]` attribute to ignore a field from being converted to `ToGodot`. #[proc_macro_derive(ToGodot, attributes(variant))] pub fn derive_to_godot(input: TokenStream) -> TokenStream { translate(input, derive::derive_to_godot) diff --git a/godot-macros/src/util/mod.rs b/godot-macros/src/util/mod.rs index 22738be05..a65511a80 100644 --- a/godot-macros/src/util/mod.rs +++ b/godot-macros/src/util/mod.rs @@ -34,12 +34,12 @@ pub fn class_name_obj(class: &impl ToTokens) -> TokenStream { pub fn property_variant_type(property_type: &impl ToTokens) -> TokenStream { let property_type = property_type.to_token_stream(); - quote! {<<#property_type as ::godot::bind::property::Property>::Intermediate as ::godot::builtin::meta::VariantMetadata>::variant_type()} + quote! { <<<#property_type as ::godot::bind::property::Property>::Intermediate as ::godot::builtin::meta::GodotConvert>::Via as ::godot::builtin::meta::GodotType>::Ffi::variant_type() } } pub fn property_variant_class_name(property_type: &impl ToTokens) -> TokenStream { let property_type = property_type.to_token_stream(); - quote! {<<#property_type as ::godot::bind::property::Property>::Intermediate as ::godot::builtin::meta::VariantMetadata>::class_name()} + quote! { <<<#property_type as ::godot::bind::property::Property>::Intermediate as ::godot::builtin::meta::GodotConvert>::Via as ::godot::builtin::meta::GodotType>::class_name() } } pub fn bail_fn(msg: impl AsRef, tokens: T) -> ParseResult diff --git a/itest/rust/src/object_tests/property_test.rs b/itest/rust/src/object_tests/property_test.rs index 494807cfc..64866a1f0 100644 --- a/itest/rust/src/object_tests/property_test.rs +++ b/itest/rust/src/object_tests/property_test.rs @@ -449,6 +449,6 @@ fn export_resource() { class.free(); } -fn check_property(property: &Dictionary, key: &str, expected: impl ToVariant) { +fn check_property(property: &Dictionary, key: &str, expected: impl ToGodot) { assert_eq!(property.get_or_nil(key), expected.to_variant()); }