Skip to content

Commit d8b3efb

Browse files
Astraleastrale-sharp
authored andcommitted
adds doc for log.rs
adds doc tests to godot-macros
1 parent ed17272 commit d8b3efb

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

godot-core/src/log.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
55
*/
66

7+
/// Pushes a warning message to Godot's built-in debugger and to the OS terminal.
8+
///
9+
/// _Godot equivalent: @GlobalScope.push_warning()_
710
#[macro_export]
811
macro_rules! godot_warn {
912
($fmt:literal $(, $args:expr)* $(,)?) => {
@@ -21,6 +24,9 @@ macro_rules! godot_warn {
2124
};
2225
}
2326

27+
/// Pushes an error message to Godot's built-in debugger and to the OS terminal.
28+
///
29+
/// _Godot equivalent: @GlobalScope.push_error()_
2430
#[macro_export]
2531
macro_rules! godot_error {
2632
// FIXME expr needs to be parenthesised, see usages
@@ -57,6 +63,9 @@ macro_rules! godot_script_error {
5763
};
5864
}
5965

66+
/// Prints to the Godot console.
67+
///
68+
/// _Godot equivalent: @GlobalScope.print()_
6069
#[macro_export]
6170
macro_rules! godot_print {
6271
($fmt:literal $(, $args:expr)* $(,)?) => {
@@ -75,6 +84,7 @@ pub use crate::{godot_error, godot_print, godot_script_error, godot_warn};
7584
use crate::builtin::{StringName, Variant};
7685
use crate::sys::{self, GodotFfi};
7786

87+
/// Prints to the Godot console, used by the godot_print! macro.
7888
pub fn print(varargs: &[Variant]) {
7989
unsafe {
8090
let method_name = StringName::from("print");

godot-macros/src/lib.rs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,83 @@
44
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
55
*/
66

7+
/// Extension API for Godot classes, used with `#[godot_api]`.
8+
///
9+
/// Helps with adding custom functionality:
10+
/// * `init` constructors
11+
/// * `to_string` method
12+
/// * Custom register methods (builder style)
13+
/// * All the lifecycle methods like `ready`, `process` etc.
14+
///
15+
/// These trait are special in that it needs to be used in combination with the `#[godot_api]`
16+
/// proc-macro attribute to ensure proper registration of its methods. All methods have
17+
/// default implementations, so you can select precisely which functionality you want to have.
18+
/// Those default implementations are never called however, the proc-macro detects what you implement.
19+
///
20+
/// Do not call any of these methods directly -- they are an interface to Godot. Functionality
21+
/// described here is available through other means (e.g. `init` via `Gd::new_default`).
22+
/// It is not enough to impl `GodotExt` to be registered in Godot, for this you should look at
23+
/// [ExtensionLibrary](crate::init::ExtensionLibrary).
24+
///
25+
/// If you wish to create a struct deriving GodotClass, you should impl the trait <Base>Virtual,
26+
/// for your desired Base (i.e. `RefCountedVirtual`, `NodeVirtual`).
27+
///
28+
/// # Examples
29+
///
30+
/// ## Example with `RefCounted` as a base
31+
///
32+
/// ```
33+
///# use godot::prelude::*;
34+
///
35+
/// #[derive(GodotClass)]
36+
/// struct MyRef;
37+
///
38+
/// #[godot_api]
39+
/// impl MyRef {
40+
/// #[func]
41+
/// pub fn hello_world(&mut self) {
42+
/// godot_print!("Hello World!")
43+
/// }
44+
/// }
45+
///
46+
/// #[godot_api]
47+
/// impl RefCountedVirtual for MyRef {
48+
/// fn init(_: Base<RefCounted>) -> Self {
49+
/// MyRef
50+
/// }
51+
/// }
52+
/// ```
53+
///
54+
/// The following example allows to use MyStruct in GDScript for instance by calling
55+
/// `MyStruct.new().hello_world()`.
56+
///
57+
///
58+
/// Note that you have to implement init otherwise you won't be able to call new or any
59+
/// other methods from GDScript.
60+
///
61+
/// ## Example with `Node` as a Base
62+
///
63+
/// ```
64+
///# use godot::prelude::*;
65+
///
66+
/// #[derive(GodotClass)]
67+
/// #[class(base=Node)]
68+
/// pub struct MyNode {
69+
/// #[base]
70+
/// base: Base<Node>,
71+
/// }
72+
///
73+
/// #[godot_api]
74+
/// impl NodeVirtual for MyNode {
75+
/// fn init(base: Base<Node>) -> Self {
76+
/// MyNode { base }
77+
/// }
78+
/// fn ready(&mut self) {
79+
/// godot_print!("Hello World!");
80+
/// }
81+
/// }
82+
/// ```
83+
///
784
use crate::util::ident;
885
use proc_macro::TokenStream;
986
use proc_macro2::TokenStream as TokenStream2;

0 commit comments

Comments
 (0)