Skip to content

Commit ada3750

Browse files
committed
Document godot_print! macros
1 parent 4ea6259 commit ada3750

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

godot-core/src/global/print.rs

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ macro_rules! inner_godot_msg {
5050

5151
/// Pushes a warning message to Godot's built-in debugger and to the OS terminal.
5252
///
53+
/// # See also
54+
/// [`godot_print!`](macro.godot_print.html) and [`godot_error!`](macro.godot_error.html).
55+
///
56+
/// Related to the utility function [`global::push_warning()`](crate::global::push_warning).
57+
///
5358
/// _Godot equivalent: [`@GlobalScope.push_warning()`](https://docs.godotengine.org/en/stable/classes/class_@globalscope.html#class-globalscope-method-push-warning)_.
5459
#[macro_export]
5560
macro_rules! godot_warn {
@@ -60,6 +65,12 @@ macro_rules! godot_warn {
6065

6166
/// Pushes an error message to Godot's built-in debugger and to the OS terminal.
6267
///
68+
/// # See also
69+
/// [`godot_print!`](macro.godot_print.html) and [`godot_warn!`](macro.godot_warn.html).
70+
/// For script errors (less relevant in Rust), use [`godot_script_error!`](macro.godot_script_error.html).
71+
///
72+
/// Related to the utility function [`global::push_error()`][crate::global::push_error].
73+
///
6374
/// _Godot equivalent: [`@GlobalScope.push_error()`](https://docs.godotengine.org/en/stable/classes/class_@globalscope.html#class-globalscope-method-push-error)_.
6475
#[macro_export]
6576
macro_rules! godot_error {
@@ -69,6 +80,13 @@ macro_rules! godot_error {
6980
}
7081

7182
/// Logs a script error to Godot's built-in debugger and to the OS terminal.
83+
///
84+
/// This is rarely needed in Rust; script errors are typically emitted by the GDScript parser.
85+
///
86+
/// # See also
87+
/// [`godot_error!`](macro.godot_error.html) for a general error message.
88+
///
89+
///
7290
#[macro_export]
7391
macro_rules! godot_script_error {
7492
($fmt:literal $(, $args:expr)* $(,)?) => {
@@ -78,6 +96,22 @@ macro_rules! godot_script_error {
7896

7997
/// Prints to the Godot console.
8098
///
99+
/// Automatically appends a newline character at the end of the message.
100+
///
101+
/// Used exactly like standard [`println!`]:
102+
/// ```no_run
103+
/// use godot::global::godot_print;
104+
///
105+
/// let version = 4;
106+
/// godot_print!("Hello, Godot {version}!");
107+
/// ```
108+
///
109+
/// # See also
110+
/// [`godot_print_rich!`](macro.godot_print_rich.html) for a slower alternative that supports BBCode, color and URL tags.
111+
/// To print Godot errors and warnings, use [`godot_error!`](macro.godot_error.html) and [`godot_warn!`](macro.godot_warn.html), respectively.
112+
///
113+
/// This uses the underlying [`global::print()`][crate::global::print] function, which takes a variable-length slice of variants.
114+
///
81115
/// _Godot equivalent: [`@GlobalScope.print()`](https://docs.godotengine.org/en/stable/classes/class_@globalscope.html#class-globalscope-method-print)_.
82116
#[macro_export]
83117
macro_rules! godot_print {
@@ -92,7 +126,7 @@ macro_rules! godot_print {
92126

93127
/// Prints to the Godot console. Supports BBCode, color and URL tags.
94128
///
95-
/// Slower than [`godot_print!`].
129+
/// Slower than [`godot_print!`](macro.godot_print_rich.html).
96130
///
97131
/// _Godot equivalent: [`@GlobalScope.print_rich()`](https://docs.godotengine.org/en/stable/classes/class_@globalscope.html#class-globalscope-method-print-rich)_.
98132
#[macro_export]
@@ -106,7 +140,24 @@ macro_rules! godot_print_rich {
106140
};
107141
}
108142

109-
/// Concatenates format-style into a `GString`.
143+
/// Concatenates format-style arguments into a `GString`.
144+
///
145+
/// Works similar to Rust's standard [`format!`] macro but returns a Godot `GString`.
146+
///
147+
/// # Example
148+
/// ```no_run
149+
/// use godot::builtin::GString;
150+
/// use godot::global::godot_str;
151+
///
152+
/// let name = "Player";
153+
/// let score = 100;
154+
/// let message: GString = godot_str!("The {name} scored {score} points!");
155+
/// ```
156+
///
157+
/// # See also
158+
/// This macro uses the underlying [`global::str()`][crate::global::str] function, which takes a variable-length slice of variants.
159+
///
160+
/// _Godot equivalent: [`@GlobalScope.str()`](https://docs.godotengine.org/en/stable/classes/class_@globalscope.html#class-globalscope-method-str)_.
110161
#[macro_export]
111162
macro_rules! godot_str {
112163
($fmt:literal $(, $args:expr)* $(,)?) => {

0 commit comments

Comments
 (0)