Skip to content

Commit 490ae0f

Browse files
bors[bot]jacobsky
andauthored
Merge #781
781: Added Godot exportable methods along with the expected signature r=jacobsky a=jacobsky Added a list of the Godot Virtual methods from Node and Control to the #[export] trait documentation. closes #672 Co-authored-by: Jacobsky <cael.jacobsen@gmail.com>
2 parents 3ddb6e6 + 3cc09db commit 490ae0f

File tree

2 files changed

+136
-15
lines changed

2 files changed

+136
-15
lines changed

gdnative-derive/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ proc-macro = true
1717
syn = { version = "1.0.74", features = ["full", "extra-traits", "visit"] }
1818
quote = "1.0.9"
1919
proc-macro2 = "1.0.28"
20+
21+
[dev-dependencies]
22+
# This is included for the doc tests.
23+
gdnative = { path = "../gdnative" }

gdnative-derive/src/lib.rs

Lines changed: 132 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ mod variant;
1919
/// Collects method signatures of all functions in a `NativeClass` that have the `#[export]` attribute and registers them with Godot.
2020
///
2121
/// For example, in the following class
22-
/// ```ignore
22+
/// ```
23+
/// use gdnative::prelude::*;
24+
///
2325
/// #[derive(NativeClass)]
2426
/// #[inherit(Reference)]
2527
/// #[no_constructor]
@@ -35,16 +37,25 @@ mod variant;
3537
///
3638
/// ```
3739
/// Will expand to
38-
/// ```ignore
40+
/// ```
41+
/// use gdnative::prelude::*;
3942
/// struct Foo{}
43+
/// impl NativeClass for Foo {
44+
/// type Base = gdnative::api::Reference;
45+
/// type UserData = gdnative::nativescript::user_data::LocalCellData<Self>;
46+
/// fn class_name() -> &'static str {
47+
/// "Foo"
48+
/// }
49+
/// }
4050
/// impl gdnative::nativescript::NativeClassMethods for Foo {
4151
/// fn register(builder: &ClassBuilder<Self>) {
4252
/// use gdnative::nativescript::init::*;
43-
/// builder.build_method("foo", gdnative::godot_wrap_method!(Foo::foo))
44-
/// .with_rpc_mode(Rpc::Disabled)
53+
/// builder.build_method("foo", gdnative::godot_wrap_method!(Foo, fn foo(&self, _owner: &Reference, bar: i64) -> i64))
54+
/// .with_rpc_mode(RpcMode::Disabled)
4555
/// .done_stateless();
4656
/// }
47-
///
57+
/// }
58+
/// impl Foo {
4859
/// fn foo(&self, _owner: &Reference, bar: i64) -> i64 {
4960
/// bar
5061
/// }
@@ -150,18 +161,27 @@ pub fn profiled(meta: TokenStream, input: TokenStream) -> TokenStream {
150161
/// Use a custom function to register signals, properties or methods, in addition
151162
/// to the one generated by `#[methods]`:
152163
///
153-
/// ```ignore
164+
/// ```
165+
/// use gdnative::prelude::*;
166+
/// use gdnative::nativescript::property::{RangeHint, FloatHint};
167+
///
154168
/// #[derive(NativeClass)]
155169
/// #[inherit(Reference)]
156-
/// #[register_with(my_register_function)]
170+
/// #[register_with(Self::my_register_function)]
157171
/// struct Foo;
158172
///
159-
/// fn my_register_function(builder: &ClassBuilder<Foo>) {
160-
/// builder.add_signal(Signal { name: "foo", args: &[] });
161-
/// builder.add_property::<f32>("bar")
162-
/// .with_getter(|_, _| 42.0)
163-
/// .with_hint(FloatHint::Range(RangeHint::new(0.0, 100.0)))
164-
/// .done();
173+
/// #[methods]
174+
/// impl Foo {
175+
/// fn new(_: &Reference) -> Self {
176+
/// Self {}
177+
/// }
178+
/// fn my_register_function(builder: &ClassBuilder<Foo>) {
179+
/// builder.add_signal(Signal { name: "foo", args: &[] });
180+
/// builder.add_property::<f32>("bar")
181+
/// .with_getter(|_, _| 42.0)
182+
/// .with_hint(FloatHint::Range(RangeHint::new(0.0, 100.0)))
183+
/// .done();
184+
/// }
165185
/// }
166186
/// ```
167187
///
@@ -220,7 +240,7 @@ pub fn profiled(meta: TokenStream, input: TokenStream) -> TokenStream {
220240
///
221241
/// ```ignore
222242
/// #[export]
223-
/// fn foo(&self, owner: &Reference)
243+
/// fn foo(&self, owner: &Reference);
224244
/// ```
225245
/// **Note**: Marking a function with `#[export]` does not have any effect unless inside an `impl` block that has the `#[methods]` attribute.
226246
///
@@ -241,9 +261,106 @@ pub fn profiled(meta: TokenStream, input: TokenStream) -> TokenStream {
241261
/// - "puppet_sync" - `RPCMode::RPC_MODE_PUPPETSYNC`
242262
///
243263
/// This enables you to set the [Multiplayer API RPC Mode](https://docs.godotengine.org/en/stable/classes/class_multiplayerapi.html?highlight=RPC#enumerations) for the function.
264+
///
244265
/// Refer to [Godot's Remote Procedure documentation](https://docs.godotengine.org/en/stable/tutorials/networking/high_level_multiplayer.html#rpc) for more details.
266+
/// #### `Node` virtual functions
245267
///
246-
268+
/// This is a list of common Godot virtual functions that are automatically called via [notifications](https://docs.godotengine.org/en/stable/classes/class_object.html#class-object-method-notification).
269+
///
270+
/// ```ignore
271+
/// fn _ready(&self, owner: &Node);
272+
/// ```
273+
/// Called when both the node and its children have entered the scene tree.
274+
/// _See [Godot docs](https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-method-ready) for more information._
275+
/// <br><br>
276+
///
277+
/// ```ignore
278+
/// fn _enter_tree(&self, owner: &Node);
279+
/// ```
280+
/// Called when the node enters the scene tree.
281+
/// _See [Godot docs](https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-method-enter-tree) for more information._
282+
/// <br><br>
283+
///
284+
/// ```ignore
285+
/// fn _exit_tree(&self, owner: &Node);
286+
/// ```
287+
/// Called when the node is removed from the scene tree.
288+
/// _See [Godot docs](https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-method-exit-tree) for more information._
289+
/// <br><br>
290+
///
291+
/// ```ignore
292+
/// fn _get_configuration_warning(&self, owner: &Node);
293+
/// ```
294+
/// The string returned from this method is displayed as a warning in the Scene Dock if the script that overrides it is a tool script.
295+
/// _See [Godot docs](https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-method-get-configuration-warning) for more information._
296+
/// <br><br>
297+
///
298+
/// ```ignore
299+
/// fn _process(&mut self, owner: &Node, delta: f64);
300+
/// ```
301+
/// Called during processing step of the main loop.
302+
/// _See [Godot docs](https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-method-process) for more information._
303+
/// <br><br>
304+
///
305+
/// ```ignore
306+
/// fn _physics_process(&self, owner: &Node, delta: f64);
307+
/// ```
308+
/// Called during physics update, with a fixed timestamp.
309+
/// _See [Godot docs](https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-method-physics-process) for more information._
310+
/// <br><br>
311+
///
312+
/// ```ignore
313+
/// fn _input(&self, owner: &Node, event: InputEvent);
314+
/// ```
315+
/// Called when there is an input event.
316+
/// _See [Godot docs](https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-method-input) for more information._
317+
/// <br><br>
318+
///
319+
/// ```ignore
320+
/// fn _unhandled_input(&self, owner: &Node, event: InputEvent);
321+
/// ```
322+
/// Called when an `InputEvent` hasn't been consumed by `_input()` or any GUI.
323+
/// _See [Godot docs](https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-method-unhandled-input) for more information._
324+
/// <br><br>
325+
///
326+
/// ```ignore
327+
/// fn _unhandled_key_input (&self, owner: &Node, event: InputKeyEvent);
328+
/// ```
329+
/// Called when an `InputEventKey` hasn't been consumed by `_input()` or any GUI.
330+
/// _See [Godot docs](https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-method-unhandled-key-input) for more information._
331+
/// <br><br>
332+
///
333+
/// #### `Control` virtual functions
334+
///
335+
/// This is a list of common Godot virtual functions that are automatically called via [notifications](https://docs.godotengine.org/en/stable/classes/class_object.html#class-object-method-notification).
336+
///
337+
/// ```ignore
338+
/// fn _clips_input(&self, owner: &Control) -> bool;
339+
/// ```
340+
/// Returns whether `_gui_input()` should not be called for children controls outside this control's rectangle.
341+
/// _See [Godot docs](https://docs.godotengine.org/en/stable/classes/class_control.html#class-control-method-clips-input) for more information._
342+
/// <br><br>
343+
///
344+
/// ```ignore
345+
/// fn _get_minimum_size(&self, owner: &Control) -> Vector2;
346+
/// ```
347+
/// Returns the minimum size for this control.
348+
/// _See [Godot docs](https://docs.godotengine.org/en/stable/classes/class_control.html#class-control-method-get-minimum-size) for more information._
349+
/// <br><br>
350+
///
351+
/// ```ignore
352+
/// fn _gui_input(&self, owner: &Control, event: InputEvent);
353+
/// ```
354+
/// Use this method to process and accept inputs on UI elements.
355+
/// _See [Godot docs](https://docs.godotengine.org/en/stable/classes/class_control.html#class-control-method-gui-input) for more information._
356+
/// <br><br>
357+
///
358+
/// ```ignore
359+
/// fn _make_custom_tooltip(&self, owner: &Control, for_text: String) -> Ref<Control>;
360+
/// ```
361+
/// Returns a `Control` node that should be used as a tooltip instead of the default one.
362+
/// _See [Godot docs](https://docs.godotengine.org/en/stable/classes/class_control.html#class-control-method-make-custom-tooltip) for more information._
363+
/// <br><br>
247364
#[proc_macro_derive(
248365
NativeClass,
249366
attributes(

0 commit comments

Comments
 (0)