Skip to content

Commit af8c1e1

Browse files
committed
Refactor get_builtin_arg_passing() to use Godot type name
1 parent f3a8fee commit af8c1e1

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

godot-codegen/src/context.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,14 @@ impl<'a> Context<'a> {
243243
self.builtin_types.contains(ty_name)
244244
}
245245

246-
pub fn get_builtin_arg_passing(&self, ty_name: &str) -> ArgPassing {
246+
pub fn get_builtin_arg_passing(&self, godot_ty: &GodotTy) -> ArgPassing {
247247
// Already handled separately.
248-
debug_assert!(!ty_name.starts_with("Packed"));
248+
debug_assert!(!godot_ty.ty.starts_with("Packed"));
249249

250250
// Arrays are also handled separately, and use ByRef.
251-
match ty_name {
252-
"Variant" | "VariantArray" | "Dictionary" => ArgPassing::ByRef,
253-
"GString" | "NodePath" | "StringName" => ArgPassing::ImplAsArg,
251+
match godot_ty.ty.as_str() {
252+
"Variant" | "Array" | "Dictionary" => ArgPassing::ByRef,
253+
"String" | "StringName" | "NodePath" => ArgPassing::ImplAsArg,
254254
_ => ArgPassing::ByValue,
255255
}
256256
}

godot-codegen/src/conv/type_conversions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ fn to_rust_type_uncached(full_ty: &GodotTy, ctx: &mut Context) -> RustTy {
179179
if let Some(hardcoded) = to_hardcoded_rust_ident(full_ty) {
180180
return RustTy::BuiltinIdent {
181181
ty: ident(hardcoded),
182-
arg_passing: ctx.get_builtin_arg_passing(hardcoded),
182+
arg_passing: ctx.get_builtin_arg_passing(full_ty),
183183
};
184184
}
185185
}
@@ -224,7 +224,7 @@ fn to_rust_type_uncached(full_ty: &GodotTy, ctx: &mut Context) -> RustTy {
224224
// Native structures might not all be Copy, but they should have value semantics.
225225
RustTy::BuiltinIdent {
226226
ty: rustify_ty(ty),
227-
arg_passing: ctx.get_builtin_arg_passing(ty),
227+
arg_passing: ctx.get_builtin_arg_passing(full_ty),
228228
}
229229
} else {
230230
let ty = rustify_ty(ty);

godot-core/src/builtin/variant/impls.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,10 @@ macro_rules! impl_ffi_variant {
130130
#[allow(clippy::module_inception)]
131131
mod impls {
132132
use super::*;
133+
134+
// IMPORTANT: the presence/absence of `ref` here should be aligned with the ArgPassing variant
135+
// used in codegen get_builtin_arg_passing().
133136

134-
// Also implements ArrayType.
135137
impl_ffi_variant!(bool, bool_to_variant, bool_from_variant);
136138
impl_ffi_variant!(i64, int_to_variant, int_from_variant; int);
137139
impl_ffi_variant!(f64, float_to_variant, float_from_variant; float);

0 commit comments

Comments
 (0)