Skip to content

Commit cc82849

Browse files
bors[bot]Bromeon
andauthored
Merge #121
121: Array/Dictionary addendum and docs, `varray!` macro r=Bromeon a=Bromeon Co-authored-by: Jan Haller <[email protected]>
2 parents 18f3a7b + eab51bf commit cc82849

File tree

17 files changed

+458
-367
lines changed

17 files changed

+458
-367
lines changed

godot-codegen/src/class_generator.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ fn make_builtin_class(
282282

283283
let methods = make_builtin_methods(&class.methods, class_name, type_info, ctx);
284284
let enums = make_enums(&class_enums, class_name, ctx);
285+
let special_constructors = make_special_builtin_methods(class_name, ctx);
285286

286287
// mod re_export needed, because class should not appear inside the file module, and we can't re-export private struct as pub
287288
let tokens = quote! {
@@ -303,7 +304,7 @@ fn make_builtin_class(
303304
sys_ptr: outer.sys(),
304305
}
305306
}
306-
307+
#special_constructors
307308
#methods
308309
}
309310

@@ -426,6 +427,24 @@ fn make_enums(enums: &Option<Vec<Enum>>, _class_name: &TyName, _ctx: &Context) -
426427
}
427428
}
428429

430+
/// Depending on the built-in class, adds custom constructors and methods.
431+
fn make_special_builtin_methods(class_name: &TyName, _ctx: &Context) -> TokenStream {
432+
if class_name.godot_ty == "Array" {
433+
quote! {
434+
pub fn from_outer_typed<T>(outer: &TypedArray<T>) -> Self
435+
where T: crate::builtin::meta::VariantMetadata
436+
{
437+
Self {
438+
_outer_lifetime: std::marker::PhantomData,
439+
sys_ptr: outer.sys(),
440+
}
441+
}
442+
}
443+
} else {
444+
TokenStream::new()
445+
}
446+
}
447+
429448
#[cfg(not(feature = "codegen-full"))]
430449
fn is_type_excluded(ty: &str, ctx: &mut Context) -> bool {
431450
let is_class_excluded = |class: &str| !crate::SELECTED_CLASSES.contains(&class);

0 commit comments

Comments
 (0)