You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// For additional details about how `#[methods]` expands, please refer to [gdnative::methods](macro@methods)
246
246
///
247
-
/// ### `#[export]`
247
+
/// ### `#[godot]`
248
248
/// Registers the attributed function signature to be used by Godot.
249
+
///
250
+
/// This attribute was formerly called `#[export]`, but is not directly related to the concept of
251
+
/// [exporting](https://docs.godotengine.org/en/stable/tutorials/export/exporting_basics.html) in GDScript.
252
+
///
249
253
/// A valid function signature must have:
250
254
/// - `&self` or `&mut self` as its first parameter
251
-
/// - `&T` or `TRef<T>` where T refers to the type declared in `#[inherit(T)]` attribute as it's second parameter; this is typically called the `owner`.
252
-
/// - Optionally, any number of additional parameters, which must have the type `Variant` or must implement the `FromVariant` trait. `FromVariant` is implemented for most common types.
255
+
/// - Optionally, `&T` or `TRef<T>` where T refers to the type declared in `#[inherit(T)]` attribute as it's second parameter;
256
+
/// this is typically called the _base_. The parameter must be attributed with `#[base]`.
257
+
/// - Any number of required parameters, which must have the type `Variant` or must implement the `FromVariant` trait.
258
+
/// `FromVariant` is implemented for most common types.
259
+
/// - Any number of optional parameters annotated with `#[opt]`. Same rules as for required parameters apply.
260
+
/// Optional parameters must appear at the end of the parameter list.
253
261
/// - Return values must implement the `OwnedToVariant` trait (automatically implemented by `ToVariant`)
254
262
/// or be a `Variant` type.
255
263
///
256
264
/// ```ignore
257
-
/// #[export]
258
-
/// fn foo(&self, owner: &Reference);
265
+
/// // No access to base parameter
266
+
/// #[godot]
267
+
/// fn foo(&self);
268
+
///
269
+
/// // Access base parameter as &T
270
+
/// #[godot]
271
+
/// fn foo(&self, #[base] base: &Reference);
272
+
///
273
+
/// // Access base parameter as TRef<T>
274
+
/// #[godot]
275
+
/// fn foo(&self, #[base] base: TRef<Reference>);
259
276
/// ```
260
-
/// **Note**: Marking a function with `#[export]` does not have any effect unless inside an `impl` block that has the `#[methods]` attribute.
261
277
///
262
-
/// Possible arguments for this attribute are
278
+
/// **Note**: Marking a function with `#[godot]` does not have any effect unless inside an `impl` block that has the `#[methods]` attribute.
279
+
///
280
+
/// Possible arguments for this attribute are:
281
+
///
282
+
/// - `name = "overridden_function_name"`
263
283
///
264
-
/// - `name` = "overridden_function_name"
284
+
/// Overrides the function name as the method name to be registered in Godot.
265
285
///
266
-
/// Overrides the function name as the method name to be registered in Godot.
286
+
/// - `rpc = "selected_rpc"`
267
287
///
268
-
/// - `rpc` = "selected_rpc"
269
-
/// - "selected_rpc" must be one of the following values, which refer to the associated [Multiplayer API RPC Mode](https://docs.godotengine.org/en/stable/classes/class_multiplayerapi.html?highlight=RPC#enumerations)
/// `"selected_rpc"` must be one of the following values, which refer to the associated [Multiplayer API RPC Mode](https://docs.godotengine.org/en/stable/classes/class_multiplayerapi.html?highlight=RPC#enumerations).
289
+
/// See also the Rust type [`export::RpcMode`].
290
+
/// - `"disabled"`
291
+
/// - `"remote"`
292
+
/// - `"remote_sync"`
293
+
/// - `"master"`
294
+
/// - `"master_sync"`
295
+
/// - `"puppet"`
296
+
/// - `"puppet_sync"`
297
+
///
298
+
/// 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.
299
+
/// Refer to [Godot's Remote Procedure documentation](https://docs.godotengine.org/en/stable/tutorials/networking/high_level_multiplayer.html#rpc) for more details.
300
+
///
301
+
/// - `deref_return`
302
+
///
303
+
/// Allows you to return a type using its `Deref` representation. This can avoid extra intermediate copies for larger objects, by explicitly
304
+
/// returning a reference (or in general, a type that dereferences to something that can be exported).
/// // Assume self.cell is std::cell::RefCell<Vec<i32>>
311
+
/// self.cell.borrow()
312
+
/// }
313
+
/// ```
277
314
///
278
-
/// 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.
279
315
///
280
-
/// Refer to [Godot's Remote Procedure documentation](https://docs.godotengine.org/en/stable/tutorials/networking/high_level_multiplayer.html#rpc) for more details.
281
316
/// #### `Node` virtual functions
282
317
///
283
318
/// 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).
284
319
///
320
+
/// It is assumed that every method is exported via `#[godot]` attribute. The parameter `#[base] base: &Node` can be omitted if you don't need it.
321
+
///
285
322
/// ```ignore
286
-
/// fn _ready(&self, owner: &Node);
323
+
/// fn _ready(&self, #[base] base: &Node);
287
324
/// ```
288
325
/// Called when both the node and its children have entered the scene tree.
289
326
/// _See [Godot docs](https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-method-ready) for more information._
290
327
/// <br><br>
291
328
///
292
329
/// ```ignore
293
-
/// fn _enter_tree(&self, owner: &Node);
330
+
/// fn _enter_tree(&self, #[base] base: &Node);
294
331
/// ```
295
332
/// Called when the node enters the scene tree.
296
333
/// _See [Godot docs](https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-method-enter-tree) for more information._
297
334
/// <br><br>
298
335
///
299
336
/// ```ignore
300
-
/// fn _exit_tree(&self, owner: &Node);
337
+
/// fn _exit_tree(&self, #[base] base: &Node);
301
338
/// ```
302
339
/// Called when the node is removed from the scene tree.
303
340
/// _See [Godot docs](https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-method-exit-tree) for more information._
/// 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.
310
347
/// _See [Godot docs](https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-method-get-configuration-warning) for more information._
/// 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).
/// Returns a `Control` node that should be used as a tooltip instead of the default one.
377
414
/// _See [Godot docs](https://docs.godotengine.org/en/stable/classes/class_control.html#class-control-method-make-custom-tooltip) for more information._
0 commit comments