@@ -84,19 +84,34 @@ macro_rules! godot_print {
84
84
( $fmt: literal $( , $args: expr) * $( , ) ?) => {
85
85
$crate:: log:: print( & [
86
86
$crate:: builtin:: Variant :: from(
87
- $crate:: builtin:: GString :: from(
88
- format!( $fmt $( , $args) * )
89
- )
87
+ format!( $fmt $( , $args) * )
90
88
)
91
89
] )
92
90
} ;
93
91
}
94
92
95
- pub use crate :: { godot_error, godot_print, godot_script_error, godot_warn} ;
93
+ /// Prints to the Godot console. Supports BBCode, color and URL tags.
94
+ ///
95
+ /// Slower than [`godot_print!`].
96
+ ///
97
+ /// _Godot equivalent: [`@GlobalScope.print_rich()`](https://docs.godotengine.org/en/stable/classes/[email protected] #class-globalscope-method-print-rich)_.
98
+ #[ macro_export]
99
+ macro_rules! godot_print_rich {
100
+ ( $fmt: literal $( , $args: expr) * $( , ) ?) => {
101
+ $crate:: log:: print_rich( & [
102
+ $crate:: builtin:: Variant :: from(
103
+ format!( $fmt $( , $args) * )
104
+ )
105
+ ] )
106
+ } ;
107
+ }
108
+
109
+ pub use crate :: { godot_error, godot_print, godot_print_rich, godot_script_error, godot_warn} ;
96
110
97
111
use crate :: builtin:: { StringName , Variant } ;
98
112
use crate :: sys:: { self , GodotFfi } ;
99
113
114
+ #[ doc( hidden) ]
100
115
/// Prints to the Godot console, used by the [`godot_print!`] macro.
101
116
pub fn print ( varargs : & [ Variant ] ) {
102
117
unsafe {
@@ -119,3 +134,27 @@ pub fn print(varargs: &[Variant]) {
119
134
// TODO use generated method, but figure out how print() with zero args can be called
120
135
// crate::engine::utilities::print(head, rest);
121
136
}
137
+
138
+ #[ doc( hidden) ]
139
+ /// Prints to the Godot console, used by the [`godot_print_rich!`] macro.
140
+ pub fn print_rich ( varargs : & [ Variant ] ) {
141
+ unsafe {
142
+ let method_name = StringName :: from ( "print_rich" ) ;
143
+ let call_fn = sys:: interface_fn!( variant_get_ptr_utility_function) (
144
+ method_name. string_sys ( ) ,
145
+ 2648703342i64 ,
146
+ ) ;
147
+ let call_fn = call_fn. unwrap_unchecked ( ) ;
148
+
149
+ let mut args = Vec :: new ( ) ;
150
+ args. extend ( varargs. iter ( ) . map ( Variant :: sys_const) ) ;
151
+
152
+ let args_ptr = args. as_ptr ( ) ;
153
+ let _variant = Variant :: from_sys_init_default ( |return_ptr| {
154
+ call_fn ( return_ptr, args_ptr, args. len ( ) as i32 ) ;
155
+ } ) ;
156
+ }
157
+
158
+ // TODO use generated method, but figure out how print_rich() with zero args can be called
159
+ // crate::engine::utilities::print_rich(head, rest);
160
+ }
0 commit comments