Skip to content

Commit 4f4ca1b

Browse files
committed
Add some pointer impls that are needed for types that are currently in codegen
1 parent 2e14deb commit 4f4ca1b

File tree

1 file changed

+24
-25
lines changed
  • godot-core/src/builtin/meta/godot_convert

1 file changed

+24
-25
lines changed

godot-core/src/builtin/meta/godot_convert/impls.rs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -274,34 +274,33 @@ impl_godot_scalar!(
274274
// void* is used by ScriptExtension::instance_create().
275275
// Other impls for raw pointers are generated for native structures.
276276

277-
impl GodotConvert for *const std::ffi::c_void {
278-
type Via = i64;
279-
}
277+
macro_rules! impl_pointer_convert {
278+
($Ptr:ty) => {
279+
impl GodotConvert for $Ptr {
280+
type Via = i64;
281+
}
280282

281-
impl ToGodot for *const std::ffi::c_void {
282-
fn to_godot(&self) -> Self::Via {
283-
*self as i64
284-
}
285-
}
283+
impl ToGodot for $Ptr {
284+
fn to_godot(&self) -> Self::Via {
285+
*self as i64
286+
}
287+
}
286288

287-
impl FromGodot for *const std::ffi::c_void {
288-
fn try_from_godot(via: Self::Via) -> Result<Self, ConvertError> {
289-
Ok(via as Self)
290-
}
289+
impl FromGodot for $Ptr {
290+
fn try_from_godot(via: Self::Via) -> Result<Self, ConvertError> {
291+
Ok(via as Self)
292+
}
293+
}
294+
};
291295
}
292296

293-
impl GodotConvert for *mut std::ffi::c_void {
294-
type Via = i64;
295-
}
297+
impl_pointer_convert!(*const std::ffi::c_void);
298+
impl_pointer_convert!(*mut std::ffi::c_void);
296299

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

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

0 commit comments

Comments
 (0)