|
1 |
| -#![macro_use] |
2 |
| - |
3 |
| -#[doc(hidden)] |
4 |
| -#[macro_export] |
5 |
| -macro_rules! godot_wrap_method_if_deref { |
6 |
| - (true, $ret:expr) => { |
7 |
| - std::ops::Deref::deref(&$ret) |
8 |
| - }; |
9 |
| - (false, $ret:expr) => { |
10 |
| - $ret |
11 |
| - }; |
12 |
| -} |
13 |
| - |
14 |
| -// The ways of emit warnings is a terrible hack. |
15 |
| -// This is because there is no way to emit warnings from macros in stable Rust. |
16 |
| -// |
17 |
| -// Follow these steps to emit warnings. |
18 |
| -// - Detect whether reference types are used in gdnative-derive::methods::derive_methods(). |
19 |
| -// - Expand the call to the deprecated_reference_return!() macro to user code. |
20 |
| -#[doc(hidden)] |
21 |
| -#[macro_export] |
22 |
| -#[deprecated = "This function does not actually pass by reference to the Godot engine. You can clarify by writing #[method(deref_return)]."] |
23 |
| -macro_rules! deprecated_reference_return { |
24 |
| - () => {}; |
25 |
| -} |
26 |
| - |
27 |
| -#[doc(hidden)] |
28 |
| -#[macro_export] |
29 |
| -#[deprecated = "\n#[export] is deprecated and will be removed in a future godot-rust version. Use #[method] instead. \n\ |
30 |
| - For more information, see https://godot-rust.github.io/docs/gdnative/derive/derive.NativeClass.html."] |
31 |
| -macro_rules! deprecated_export_syntax { |
32 |
| - () => {}; |
33 |
| -} |
34 |
| - |
35 |
| -#[doc(hidden)] |
36 |
| -#[macro_export] |
37 |
| -macro_rules! godot_wrap_method_void { |
38 |
| - ($ident:ident, $void:tt) => { |
39 |
| - $ident |
40 |
| - }; |
41 |
| -} |
42 |
| - |
43 |
| -#[doc(hidden)] |
44 |
| -#[macro_export] |
45 |
| -macro_rules! godot_wrap_method_inner { |
46 |
| - ( |
47 |
| - $type_name:ty, |
48 |
| - $is_deref_return:ident, |
49 |
| - $map_method:ident, |
50 |
| - fn $method_name:ident( |
51 |
| - $self:ident |
52 |
| - $(, #[base] $base:ident : $base_ty:ty)? |
53 |
| - $(, $pname:ident : $pty:ty)* |
54 |
| - $(, #[opt] $opt_pname:ident : $opt_pty:ty)* |
55 |
| - ) -> $retty:ty |
56 |
| - ) => { |
57 |
| - { |
58 |
| - #[derive(Copy, Clone, Default)] |
59 |
| - struct ThisMethod; |
60 |
| - |
61 |
| - use $crate::export::{NativeClass, OwnerArg}; |
62 |
| - use $crate::object::{Instance, TInstance}; |
63 |
| - use ::gdnative::derive::FromVarargs; |
64 |
| - |
65 |
| - #[derive(FromVarargs)] |
66 |
| - #[allow(clippy::used_underscore_binding)] |
67 |
| - struct Args { |
68 |
| - $($pname: $pty,)* |
69 |
| - $(#[opt] $opt_pname: $opt_pty,)* |
70 |
| - } |
71 |
| - |
72 |
| - #[allow(unused_variables, unused_assignments, unused_mut)] |
73 |
| - impl $crate::export::StaticArgsMethod<$type_name> for ThisMethod { |
74 |
| - type Args = Args; |
75 |
| - fn call( |
76 |
| - &self, |
77 |
| - this: TInstance<'_, $type_name, $crate::object::ownership::Shared>, |
78 |
| - Args { $($pname,)* $($opt_pname,)* }: Args, |
79 |
| - ) -> $crate::core_types::Variant { |
80 |
| - this |
81 |
| - .$map_method(|__rust_val, __base| { |
82 |
| - #[allow(unused_unsafe)] |
83 |
| - unsafe { |
84 |
| - let ret = __rust_val.$method_name( |
85 |
| - $(OwnerArg::from_safe_ref($crate::godot_wrap_method_void!(__base,$base)),)? |
86 |
| - $($pname,)* |
87 |
| - $($opt_pname,)* |
88 |
| - ); |
89 |
| - gdnative::core_types::OwnedToVariant::owned_to_variant( |
90 |
| - $crate::godot_wrap_method_if_deref!($is_deref_return, ret) |
91 |
| - ) |
92 |
| - } |
93 |
| - }) |
94 |
| - .unwrap_or_else(|err| { |
95 |
| - $crate::godot_error!("gdnative-core: method call failed with error: {}", err); |
96 |
| - $crate::godot_error!("gdnative-core: check module level documentation on gdnative::user_data for more information"); |
97 |
| - $crate::core_types::Variant::nil() |
98 |
| - }) |
99 |
| - } |
100 |
| - |
101 |
| - fn site() -> Option<$crate::log::Site<'static>> { |
102 |
| - Some($crate::godot_site!($type_name::$method_name)) |
103 |
| - } |
104 |
| - } |
105 |
| - |
106 |
| - $crate::export::StaticArgs::new(ThisMethod) |
107 |
| - } |
108 |
| - }; |
109 |
| -} |
110 |
| - |
111 |
| -#[doc(hidden)] |
112 |
| -#[macro_export] |
113 |
| -macro_rules! godot_wrap_method_return_type { |
114 |
| - () => { |
115 |
| - () |
116 |
| - }; |
117 |
| - ($retty:ty) => { |
118 |
| - $retty: ty |
119 |
| - }; |
120 |
| -} |
121 |
| - |
122 |
| -/// Convenience macro to wrap an object's method into a function pointer |
123 |
| -/// that can be passed to the engine when registering a class. |
124 |
| -#[macro_export] |
125 |
| -macro_rules! godot_wrap_method { |
126 |
| - // mutable |
127 |
| - ( |
128 |
| - $type_name:ty, |
129 |
| - $is_deref_return:ident, |
130 |
| - fn $method_name:ident( |
131 |
| - &mut $self:ident |
132 |
| - $(, #[base] $base:ident : $base_ty:ty)? |
133 |
| - $(, $pname:ident : $pty:ty)* |
134 |
| - $(, #[opt] $opt_pname:ident : $opt_pty:ty)* |
135 |
| - $(,)? |
136 |
| - ) $(-> $retty:ty)? |
137 |
| - ) => { |
138 |
| - $crate::godot_wrap_method_inner!( |
139 |
| - $type_name, |
140 |
| - $is_deref_return, |
141 |
| - map_mut, |
142 |
| - fn $method_name( |
143 |
| - $self |
144 |
| - $(, #[base] $base : $base_ty)? |
145 |
| - $(, $pname : $pty)* |
146 |
| - $(, #[opt] $opt_pname : $opt_pty)* |
147 |
| - ) -> godot_wrap_method_return_type!($($retty)?) |
148 |
| - ) |
149 |
| - }; |
150 |
| - // immutable |
151 |
| - ( |
152 |
| - $type_name:ty, |
153 |
| - $is_deref_return:ident, |
154 |
| - fn $method_name:ident( |
155 |
| - & $self:ident |
156 |
| - $(, #[base] $base:ident : $base_ty:ty)? |
157 |
| - $(, $pname:ident : $pty:ty)* |
158 |
| - $(, #[opt] $opt_pname:ident : $opt_pty:ty)* |
159 |
| - $(,)? |
160 |
| - ) $(-> $retty:ty)? |
161 |
| - ) => { |
162 |
| - $crate::godot_wrap_method_inner!( |
163 |
| - $type_name, |
164 |
| - $is_deref_return, |
165 |
| - map, |
166 |
| - fn $method_name( |
167 |
| - $self |
168 |
| - $(, #[base] $base : $base_ty)? |
169 |
| - $(, $pname : $pty)* |
170 |
| - $(, #[opt] $opt_pname : $opt_pty)* |
171 |
| - ) -> godot_wrap_method_return_type!($($retty)?) |
172 |
| - ) |
173 |
| - }; |
174 |
| - // owned |
175 |
| - ( |
176 |
| - $type_name:ty, |
177 |
| - $is_deref_return:ident, |
178 |
| - fn $method_name:ident( |
179 |
| - mut $self:ident |
180 |
| - $(, #[base] $base:ident : $base_ty:ty)? |
181 |
| - $(, $pname:ident : $pty:ty)* |
182 |
| - $(, #[opt] $opt_pname:ident : $opt_pty:ty)* |
183 |
| - $(,)? |
184 |
| - ) $(-> $retty:ty)? |
185 |
| - ) => { |
186 |
| - $crate::godot_wrap_method_inner!( |
187 |
| - $type_name, |
188 |
| - $is_deref_return, |
189 |
| - map_owned, |
190 |
| - fn $method_name( |
191 |
| - $self |
192 |
| - $(, #[base] $base : $base_ty)? |
193 |
| - $(, $pname : $pty)* |
194 |
| - $(, #[opt] $opt_pname : $opt_pty)* |
195 |
| - ) -> godot_wrap_method_return_type!($($retty)?) |
196 |
| - ) |
197 |
| - }; |
198 |
| - // owned |
199 |
| - ( |
200 |
| - $type_name:ty, |
201 |
| - $is_deref_return:ident, |
202 |
| - fn $method_name:ident( |
203 |
| - $self:ident |
204 |
| - $(, #[base] $base:ident : $base_ty:ty)? |
205 |
| - $(, $pname:ident : $pty:ty)* |
206 |
| - $(, #[opt] $opt_pname:ident : $opt_pty:ty)* |
207 |
| - $(,)? |
208 |
| - ) $(-> $retty:ty)? |
209 |
| - ) => { |
210 |
| - $crate::godot_wrap_method_inner!( |
211 |
| - $type_name, |
212 |
| - $is_deref_return, |
213 |
| - map_owned, |
214 |
| - fn $method_name( |
215 |
| - $self |
216 |
| - $(, #[base] $base : $base_ty)? |
217 |
| - $(, $pname : $pty)* |
218 |
| - $(, #[opt] $opt_pname : $opt_pty)* |
219 |
| - ) -> godot_wrap_method_return_type!($($retty)?) |
220 |
| - ) |
221 |
| - }; |
222 |
| -} |
| 1 | +#[doc(inline)] |
| 2 | +pub use gdnative_derive::godot_wrap_method; |
0 commit comments