Skip to content

Add some missing godot-convert impls for pointers #679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 24 additions & 25 deletions godot-core/src/builtin/meta/godot_convert/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,34 +274,33 @@ impl_godot_scalar!(
// void* is used by ScriptExtension::instance_create().
// Other impls for raw pointers are generated for native structures.

impl GodotConvert for *const std::ffi::c_void {
type Via = i64;
}
macro_rules! impl_pointer_convert {
($Ptr:ty) => {
impl GodotConvert for $Ptr {
type Via = i64;
}

impl ToGodot for *const std::ffi::c_void {
fn to_godot(&self) -> Self::Via {
*self as i64
}
}
impl ToGodot for $Ptr {
fn to_godot(&self) -> Self::Via {
*self as i64
}
}

impl FromGodot for *const std::ffi::c_void {
fn try_from_godot(via: Self::Via) -> Result<Self, ConvertError> {
Ok(via as Self)
}
impl FromGodot for $Ptr {
fn try_from_godot(via: Self::Via) -> Result<Self, ConvertError> {
Ok(via as Self)
}
}
};
}

impl GodotConvert for *mut std::ffi::c_void {
type Via = i64;
}
impl_pointer_convert!(*const std::ffi::c_void);
impl_pointer_convert!(*mut std::ffi::c_void);

impl ToGodot for *mut std::ffi::c_void {
fn to_godot(&self) -> Self::Via {
*self as i64
}
}
// Some other pointer types are used by various other methods, see https://github.com/godot-rust/gdext/issues/677
// TODO: Find better solution to this, this may easily break still if godot decides to add more pointer arguments.

impl FromGodot for *mut std::ffi::c_void {
fn try_from_godot(via: Self::Via) -> Result<Self, ConvertError> {
Ok(via as Self)
}
}
impl_pointer_convert!(*mut *const u8);
impl_pointer_convert!(*mut i32);
impl_pointer_convert!(*mut f64);
impl_pointer_convert!(*mut u8);
Loading