Skip to content

Commit

Permalink
Final fixes after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
lilizoey committed Oct 13, 2023
1 parent 30153f7 commit 2a103a0
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 9 deletions.
6 changes: 3 additions & 3 deletions godot-core/src/builtin/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>`, where the type `T` implements `VariantMetadata`, `FromGodot` and `ToGodot`.
/// `Array<T>`, where the type `T` implements `GodotType`.
///
/// # Reference semantics
///
Expand All @@ -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<T: GodotType> {
opaque: sys::types::OpaqueArray,
Expand Down
21 changes: 21 additions & 0 deletions godot-core/src/builtin/meta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ pub trait GodotType: GodotConvert<Via = Self> + 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()
}
Expand Down Expand Up @@ -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<MethodParamOrReturnInfo> {
T::return_info()
}
}

// ----------------------------------------------------------------------------------------------------------------------------------------------
Expand Down
9 changes: 7 additions & 2 deletions godot-core/src/obj/gd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,11 @@ impl<T: GodotClass> GodotType for Gd<T> {
Some(Self { raw })
}
}

fn class_name() -> crate::builtin::meta::ClassName {
println!("class_name gd");
T::class_name()
}
}

impl<T: GodotClass> Clone for Gd<T> {
Expand Down Expand Up @@ -540,13 +545,13 @@ impl<T: GodotClass> Eq for Gd<T> {}

impl<T: GodotClass> Display for Gd<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
engine::display_string(&self, f)
engine::display_string(self, f)
}
}

impl<T: GodotClass> Debug for Gd<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
engine::debug_string(&self, f, "Gd")
engine::debug_string(self, f, "Gd")
}
}

Expand Down
2 changes: 2 additions & 0 deletions godot-core/src/obj/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ impl<T: GodotClass> GodotType for RawGd<T> {
}

fn class_name() -> ClassName {
println!("class_name gd");

T::class_name()
}
}
Expand Down
2 changes: 1 addition & 1 deletion godot-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions godot-macros/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<R, T>(msg: impl AsRef<str>, tokens: T) -> ParseResult<R>
Expand Down
2 changes: 1 addition & 1 deletion itest/rust/src/object_tests/property_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

0 comments on commit 2a103a0

Please sign in to comment.