Skip to content

Commit ca371c1

Browse files
authored
PropertyInfo class_name should come from property object (#57)
1 parent 6c732ad commit ca371c1

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

derive/src/impl_attribute.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub fn godot_script_impl(
5757
.enumerate()
5858
.map(|(index, arg)| {
5959
let arg_name = arg.pat.as_ref();
60+
let arg_rust_type = arg.ty.as_ref();
6061
let arg_type = rust_to_variant_type(arg.ty.as_ref()).unwrap();
6162

6263
is_context_type(arg.ty.as_ref()).then(|| {
@@ -72,6 +73,7 @@ pub fn godot_script_impl(
7273
::godot_rust_script::private_export::RustScriptPropDesc {
7374
name: stringify!(#arg_name),
7475
ty: #arg_type,
76+
class_name: <<#arg_rust_type as #godot_types::meta::GodotConvert>::Via as #godot_types::meta::GodotType>::class_name(),
7577
exported: false,
7678
hint: #property_hints::NONE,
7779
hint_string: String::new(),
@@ -132,6 +134,7 @@ pub fn godot_script_impl(
132134
return_type: ::godot_rust_script::private_export::RustScriptPropDesc {
133135
name: #fn_name_str,
134136
ty: #fn_return_ty,
137+
class_name: <<#fn_return_ty_rust as #godot_types::meta::GodotConvert>::Via as #godot_types::meta::GodotType>::class_name(),
135138
exported: false,
136139
hint: #property_hints::NONE,
137140
hint_string: String::new(),

derive/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,15 @@ fn derive_field_metadata(
372372
field: &SpannedValue<FieldOpts>,
373373
is_exported: bool,
374374
) -> Result<TokenStream, TokenStream> {
375+
let godot_types = godot_types();
375376
let property_hint_ty = property_hints();
376377
let name = field
377378
.ident
378379
.as_ref()
379380
.map(|field| field.to_string())
380381
.unwrap_or_default();
381382

383+
let rust_ty = &field.ty;
382384
let ty = rust_to_variant_type(&field.ty)?;
383385

384386
let (hint, hint_string) = is_exported
@@ -401,6 +403,7 @@ fn derive_field_metadata(
401403
::godot_rust_script::private_export::RustScriptPropDesc {
402404
name: #name,
403405
ty: #ty,
406+
class_name: <<#rust_ty as #godot_types::meta::GodotConvert>::Via as #godot_types::meta::GodotType>::class_name(),
404407
exported: #is_exported,
405408
hint: #hint,
406409
hint_string: #hint_string,

rust-script/src/interface/signals.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ macro_rules! signal_argument_desc {
124124
RustScriptPropDesc {
125125
name: $name,
126126
ty: <<<$type as GodotConvert>::Via as GodotType>::Ffi as godot::sys::GodotFfi>::variant_type(),
127+
class_name: <<$type as GodotConvert>::Via as GodotType>::class_name(),
127128
exported: false,
128129
hint: PropertyHint::NONE,
129130
hint_string: String::new(),

rust-script/src/runtime/metadata.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use std::ops::Deref;
88

9-
use godot::meta::{MethodInfo, PropertyInfo};
9+
use godot::meta::{ClassName, MethodInfo, PropertyInfo};
1010
use godot::obj::{EngineBitfield, EngineEnum};
1111
use godot::prelude::{Array, Dictionary};
1212
use godot::sys::VariantType;
@@ -93,6 +93,13 @@ fn variant_type_to_str(var_type: VariantType) -> &'static str {
9393
}
9494
}
9595

96+
fn prop_doc_type(prop_type: VariantType, class_name: ClassName) -> &'static str {
97+
match prop_type {
98+
VariantType::OBJECT => class_name.as_str(),
99+
_ => variant_type_to_str(prop_type),
100+
}
101+
}
102+
96103
pub trait ToMethodDoc {
97104
fn to_method_doc(&self) -> Dictionary;
98105
}
@@ -109,7 +116,7 @@ impl ToMethodDoc for MethodInfo {
109116
dict.set("name", self.method_name.clone());
110117
dict.set(
111118
"return_type",
112-
variant_type_to_str(self.return_type.variant_type),
119+
prop_doc_type(self.return_type.variant_type, self.return_type.class_name),
113120
);
114121
dict.set("is_deprecated", false);
115122
dict.set("is_experimental", false);
@@ -184,7 +191,7 @@ impl ToArgumentDoc for PropertyInfo {
184191
fn to_argument_doc(&self) -> Dictionary {
185192
Dictionary::new().apply(|dict| {
186193
dict.set("name", self.property_name.clone());
187-
dict.set("type", variant_type_to_str(self.variant_type));
194+
dict.set("type", prop_doc_type(self.variant_type, self.class_name));
188195
})
189196
}
190197
}
@@ -205,7 +212,7 @@ impl ToPropertyDoc for PropertyInfo {
205212
fn to_property_doc(&self) -> Dictionary {
206213
Dictionary::new().apply(|dict| {
207214
dict.set("name", self.property_name.clone());
208-
dict.set("type", variant_type_to_str(self.variant_type));
215+
dict.set("type", prop_doc_type(self.variant_type, self.class_name));
209216
dict.set("is_deprecated", false);
210217
dict.set("is_experimental", false);
211218
})

rust-script/src/static_script_registry.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,18 @@ pub enum RegistryItem {
8080
pub struct RustScriptPropDesc {
8181
pub name: &'static str,
8282
pub ty: VariantType,
83+
pub class_name: ClassName,
8384
pub exported: bool,
8485
pub hint: PropertyHint,
8586
pub hint_string: String,
8687
pub description: &'static str,
8788
}
8889

8990
impl RustScriptPropDesc {
90-
pub fn to_property_info(&self, class_name: &'static str) -> RustScriptPropertyInfo {
91+
pub fn to_property_info(&self) -> RustScriptPropertyInfo {
9192
RustScriptPropertyInfo {
9293
variant_type: self.ty,
93-
class_name,
94+
class_name: self.class_name,
9495
property_name: self.name,
9596
usage: if self.exported {
9697
(PropertyUsageFlags::EDITOR | PropertyUsageFlags::STORAGE).ord()
@@ -118,12 +119,12 @@ impl RustScriptMethodDesc {
118119
id,
119120
method_name: self.name,
120121
class_name,
121-
return_type: self.return_type.to_property_info(class_name),
122+
return_type: self.return_type.to_property_info(),
122123
flags: self.flags.ord(),
123124
arguments: self
124125
.arguments
125126
.iter()
126-
.map(|arg| arg.to_property_info(class_name))
127+
.map(|arg| arg.to_property_info())
127128
.collect(),
128129
description: self.description,
129130
}
@@ -143,7 +144,7 @@ impl From<RustScriptSignalDesc> for RustScriptSignalInfo {
143144
arguments: value
144145
.arguments
145146
.iter()
146-
.map(|arg| arg.to_property_info("\0"))
147+
.map(|arg| arg.to_property_info())
147148
.collect(),
148149
description: value.description,
149150
}
@@ -174,7 +175,7 @@ pub fn assemble_metadata<'a>(
174175
.map(|class| {
175176
let props = (class.properties)()
176177
.into_iter()
177-
.map(|prop| prop.to_property_info(class.class_name))
178+
.map(|prop| prop.to_property_info())
178179
.collect();
179180

180181
let methods = methods
@@ -210,7 +211,7 @@ pub fn assemble_metadata<'a>(
210211
pub struct RustScriptPropertyInfo {
211212
pub variant_type: VariantType,
212213
pub property_name: &'static str,
213-
pub class_name: &'static str,
214+
pub class_name: ClassName,
214215
pub hint: i32,
215216
pub hint_string: String,
216217
pub usage: u64,
@@ -222,7 +223,7 @@ impl From<&RustScriptPropertyInfo> for PropertyInfo {
222223
Self {
223224
variant_type: value.variant_type,
224225
property_name: value.property_name.into(),
225-
class_name: ClassName::from_ascii_cstr(value.class_name.as_bytes()),
226+
class_name: value.class_name,
226227
hint: PropertyHint::try_from_ord(value.hint).unwrap_or(PropertyHint::NONE),
227228
hint_string: value.hint_string.to_godot(),
228229
usage: PropertyUsageFlags::try_from_ord(value.usage)

0 commit comments

Comments
 (0)