Skip to content

Commit bdd6ecd

Browse files
committed
Shim legacy init macros whenever possible.
1 parent 687dcf4 commit bdd6ecd

File tree

3 files changed

+81
-3
lines changed

3 files changed

+81
-3
lines changed

gdnative-core/src/init/macros.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,77 @@ macro_rules! godot_init {
2121
};
2222
};
2323
}
24+
25+
/// Legacy macro that declares all the API endpoints necessary to initialize a NativeScript library.
26+
///
27+
/// This is a shim for the new [`#[gdnative::init::callbacks]`][crate::init::callbacks] attribute
28+
/// macro, which is now used to declare API callbacks along with the
29+
/// [`GDNativeCallbacks`][crate::init::GDNativeCallbacks] trait.
30+
#[macro_export]
31+
#[deprecated = "use the #[gdnative::init::callbacks] attribute macro instead"]
32+
macro_rules! godot_nativescript_init {
33+
() => {
34+
const _: () = {
35+
struct GDNativeCallbacksImpl;
36+
37+
#[$crate::init::callbacks]
38+
unsafe impl $crate::init::GDNativeCallbacks for GDNativeCallbacksImpl {}
39+
};
40+
};
41+
($callback:ident) => {
42+
const _: () = {
43+
struct GDNativeCallbacksImpl;
44+
45+
#[$crate::init::callbacks]
46+
unsafe impl $crate::init::GDNativeCallbacks for GDNativeCallbacksImpl {
47+
fn nativescript_init(handle: $crate::init::InitHandle) {
48+
$callback(handle);
49+
}
50+
}
51+
};
52+
};
53+
(_ as $fn_name:ident) => {
54+
::std::compile_error!("this syntax is no longer supported. use the #[gdnative::init::callbacks] attribute macro with a prefix instead");
55+
};
56+
($callback:ident as $fn_name:ident) => {
57+
::std::compile_error!("this syntax is no longer supported. use the #[gdnative::init::callbacks] attribute macro with a prefix instead");
58+
};
59+
}
60+
61+
/// This macro now does nothing. It is provided only for limited backwards compatibility.
62+
///
63+
/// Use the new [`#[gdnative::init::callbacks]`][crate::init::callbacks] attribute macro and,
64+
/// [`GDNativeCallbacks`][crate::init::GDNativeCallbacks] trait instead.
65+
#[macro_export]
66+
#[deprecated = "use the #[gdnative::init::callbacks] attribute macro instead"]
67+
macro_rules! godot_gdnative_init {
68+
() => {};
69+
($callback:ident) => {
70+
::std::compile_error!("this syntax is no longer supported. use the #[gdnative::init::callbacks] attribute macro instead");
71+
};
72+
(_ as $fn_name:ident) => {
73+
::std::compile_error!("this syntax is no longer supported. use the #[gdnative::init::callbacks] attribute macro with a prefix instead");
74+
};
75+
($callback:ident as $fn_name:ident) => {
76+
::std::compile_error!("this syntax is no longer supported. use the #[gdnative::init::callbacks] attribute macro with a prefix instead");
77+
};
78+
}
79+
80+
/// This macro now does nothing. It is provided only for limited backwards compatibility.
81+
///
82+
/// Use the new [`#[gdnative::init::callbacks]`][crate::init::callbacks] attribute macro and,
83+
/// [`GDNativeCallbacks`][crate::init::GDNativeCallbacks] trait instead.
84+
#[macro_export]
85+
#[deprecated = "use the #[gdnative::init::callbacks] attribute macro instead"]
86+
macro_rules! godot_gdnative_terminate {
87+
() => {};
88+
($callback:ident) => {
89+
::std::compile_error!("this syntax is no longer supported. use the #[gdnative::init::callbacks] attribute macro instead");
90+
};
91+
(_ as $fn_name:ident) => {
92+
::std::compile_error!("this syntax is no longer supported. use the #[gdnative::init::callbacks] attribute macro with a prefix instead");
93+
};
94+
($callback:ident as $fn_name:ident) => {
95+
::std::compile_error!("this syntax is no longer supported. use the #[gdnative::init::callbacks] attribute macro with a prefix instead");
96+
};
97+
}

gdnative-core/src/init/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ pub fn auto_register(_init_handle: InitHandle) {
204204
}
205205

206206
#[allow(deprecated)]
207-
pub use crate::godot_init;
207+
pub use crate::{
208+
godot_gdnative_init, godot_gdnative_terminate, godot_init, godot_nativescript_init,
209+
};
208210

209211
#[doc(inline)]
210212
pub use gdnative_derive::callbacks;

gdnative/src/prelude.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ pub use gdnative_core::export::{
1616
ClassBuilder, ExportInfo, Method, MethodBuilder, NativeClass, NativeClassMethods, Property,
1717
PropertyUsage, SignalBuilder, SignalParam,
1818
};
19-
#[allow(deprecated)]
20-
pub use gdnative_core::godot_init;
2119
pub use gdnative_core::init::{GDNativeCallbacks, InitHandle};
2220
pub use gdnative_core::object::{
2321
memory::{ManuallyManaged, RefCounted},
@@ -26,6 +24,10 @@ pub use gdnative_core::object::{
2624
TRef,
2725
};
2826
pub use gdnative_core::{godot_dbg, godot_error, godot_print, godot_warn};
27+
#[allow(deprecated)]
28+
pub use gdnative_core::{
29+
godot_gdnative_init, godot_gdnative_terminate, godot_init, godot_nativescript_init,
30+
};
2931
pub use gdnative_derive::*;
3032

3133
/// User-data attributes from [`export::user_data`][crate::export::user_data] module.

0 commit comments

Comments
 (0)