@@ -102,13 +102,7 @@ macro_rules! godot_gdnative_terminate {
102
102
#[ macro_export]
103
103
macro_rules! godot_print {
104
104
( $( $args: tt) * ) => ( {
105
- let msg = format!( $( $args) * ) ;
106
-
107
- #[ allow( unused_unsafe) ]
108
- unsafe {
109
- let msg = $crate:: core_types:: GodotString :: from_str( msg) ;
110
- ( $crate:: private:: get_api( ) . godot_print) ( & msg. to_sys( ) as * const _) ;
111
- }
105
+ $crate:: log:: print( :: std:: format_args!( $( $args) * ) ) ;
112
106
} ) ;
113
107
}
114
108
@@ -139,6 +133,51 @@ macro_rules! godot_dbg {
139
133
} ;
140
134
}
141
135
136
+ /// Creates a `gdnative::log::Site` value from the current position in code,
137
+ /// optionally with a function path for identification.
138
+ ///
139
+ /// # Examples
140
+ ///
141
+ /// ```ignore
142
+ /// // WARN: <unset>: foo At: path/to/file.rs:123
143
+ /// gdnative::log::warn(godot_site!(), "foo");
144
+ /// // WARN: Foo::my_func: bar At: path/to/file.rs:123
145
+ /// gdnative::log::error(godot_site!(Foo::my_func), "bar");
146
+ /// ```
147
+ #[ macro_export]
148
+ macro_rules! godot_site {
149
+ ( ) => { {
150
+ // SAFETY: I guess we can assume that all sane file systems don't allow
151
+ // NUL-bytes in paths?
152
+ #[ allow( unused_unsafe) ]
153
+ let site: $crate:: log:: Site <' static > = unsafe {
154
+ let file = :: std:: ffi:: CStr :: from_bytes_with_nul_unchecked(
155
+ :: std:: concat!( :: std:: file!( ) , "\0 " ) . as_bytes( ) ,
156
+ ) ;
157
+ let func = :: std:: ffi:: CStr :: from_bytes_with_nul_unchecked( b"<unset>\0 " ) ;
158
+ $crate:: log:: Site :: new( file, func, :: std:: line!( ) )
159
+ } ;
160
+
161
+ site
162
+ } } ;
163
+ ( $( $path: tt) +) => { {
164
+ // SAFETY: I guess we can assume that all sane file systems don't allow
165
+ // NUL-bytes in paths?
166
+ #[ allow( unused_unsafe) ]
167
+ let site: $crate:: log:: Site <' static > = unsafe {
168
+ let file = :: std:: ffi:: CStr :: from_bytes_with_nul_unchecked(
169
+ :: std:: concat!( :: std:: file!( ) , "\0 " ) . as_bytes( ) ,
170
+ ) ;
171
+ let func = :: std:: ffi:: CStr :: from_bytes_with_nul_unchecked(
172
+ :: std:: concat!( :: std:: stringify!( $( $path) +) , "\0 " ) . as_bytes( ) ,
173
+ ) ;
174
+ $crate:: log:: Site :: new( file, func, :: std:: line!( ) )
175
+ } ;
176
+
177
+ site
178
+ } } ;
179
+ }
180
+
142
181
/// Print a warning using the engine's logging system (visible in the editor).
143
182
///
144
183
/// # Guarantees
@@ -150,22 +189,8 @@ macro_rules! godot_dbg {
150
189
#[ macro_export]
151
190
macro_rules! godot_warn {
152
191
( $( $args: tt) * ) => ( {
153
- let msg = format!( $( $args) * ) ;
154
- let line = line!( ) ;
155
- let file = file!( ) ;
156
- #[ allow( unused_unsafe) ]
157
- unsafe {
158
- let msg = :: std:: ffi:: CString :: new( msg) . unwrap( ) ;
159
- let file = :: std:: ffi:: CString :: new( file) . unwrap( ) ;
160
- let func = b"<native>\0 " ;
161
- ( $crate:: private:: get_api( ) . godot_print_warning) (
162
- msg. as_ptr( ) as * const _,
163
- func. as_ptr( ) as * const _,
164
- file. as_ptr( ) as * const _,
165
- line as _,
166
- ) ;
167
- }
168
- } )
192
+ $crate:: log:: warn( $crate:: godot_site!( ) , :: std:: format_args!( $( $args) * ) ) ;
193
+ } ) ;
169
194
}
170
195
171
196
/// Print an error using the engine's logging system (visible in the editor).
@@ -179,22 +204,8 @@ macro_rules! godot_warn {
179
204
#[ macro_export]
180
205
macro_rules! godot_error {
181
206
( $( $args: tt) * ) => ( {
182
- let msg = format!( $( $args) * ) ;
183
- let line = line!( ) ;
184
- let file = file!( ) ;
185
- #[ allow( unused_unsafe) ]
186
- unsafe {
187
- let msg = :: std:: ffi:: CString :: new( msg) . unwrap( ) ;
188
- let file = :: std:: ffi:: CString :: new( file) . unwrap( ) ;
189
- let func = b"<native>\0 " ;
190
- ( $crate:: private:: get_api( ) . godot_print_error) (
191
- msg. as_ptr( ) as * const _,
192
- func. as_ptr( ) as * const _,
193
- file. as_ptr( ) as * const _,
194
- line as _,
195
- ) ;
196
- }
197
- } )
207
+ $crate:: log:: error( $crate:: godot_site!( ) , :: std:: format_args!( $( $args) * ) ) ;
208
+ } ) ;
198
209
}
199
210
200
211
macro_rules! impl_basic_trait_as_sys {
0 commit comments