Skip to content

Commit

Permalink
Add support for typed arrays
Browse files Browse the repository at this point in the history
- Rename `Array` to `TypedArray<T>`
- Check/set runtime type of the underlying Godot `Array`
- Make all parameters and return values `T` instead of `Variant`
- Add `Array` as an alias for `TypedArray<Variant>`
- Add `array!` macro and use it in tests
- Add `array!` and also `dict!` in the prelude

See godot-rust#33 for design discussion
  • Loading branch information
ttencate committed Feb 5, 2023
1 parent 17487d6 commit 74b729a
Show file tree
Hide file tree
Showing 15 changed files with 913 additions and 454 deletions.
8 changes: 6 additions & 2 deletions godot-codegen/src/class_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,17 @@ fn make_builtin_class(
sys_ptr: sys::GDExtensionTypePtr,
}
impl<'a> #inner_class<'a> {
pub fn from_outer(outer: &#outer_class) -> Self {
pub fn from_sys_ptr(sys_ptr: sys::GDExtensionTypePtr) -> Self {
Self {
_outer_lifetime: std::marker::PhantomData,
sys_ptr: outer.sys(),
sys_ptr,
}
}

pub fn from_outer(outer: &#outer_class) -> Self {
Self::from_sys_ptr(outer.sys())
}

#methods
}

Expand Down
6 changes: 6 additions & 0 deletions godot-codegen/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ pub fn make_enum_definition(enum_: &Enum) -> TokenStream {
Self { ord: self.ord | rhs.ord }
}
}

impl Default for #enum_name {
fn default() -> Self {
Self { ord: 0 }
}
}
};

Some(tokens)
Expand Down
Loading

0 comments on commit 74b729a

Please sign in to comment.