@@ -15,6 +15,12 @@ pub mod log;
15
15
pub mod obj;
16
16
pub mod property;
17
17
18
+ #[ doc( hidden) ]
19
+ #[ path = "deprecated.rs" ]
20
+ pub mod __deprecated;
21
+ #[ doc( hidden) ]
22
+ pub mod private;
23
+
18
24
pub use godot_ffi as sys;
19
25
#[ doc( hidden) ]
20
26
pub use godot_ffi:: out;
@@ -44,163 +50,6 @@ pub mod engine;
44
50
mod gen;
45
51
46
52
47
- #[ doc( hidden) ]
48
- pub mod private {
49
- use std:: sync:: { Arc , Mutex } ;
50
-
51
- pub use crate :: gen:: classes:: class_macros;
52
- pub use crate :: registry:: { callbacks, ClassPlugin , ErasedRegisterFn , PluginItem } ;
53
- pub use crate :: storage:: { as_storage, Storage } ;
54
- pub use sys:: out;
55
-
56
- use crate :: { log, sys} ;
57
-
58
- // If someone forgets #[godot_api], this causes a compile error, rather than virtual functions not being called at runtime.
59
- #[ allow( non_camel_case_types) ]
60
- pub trait You_forgot_the_attribute__godot_api { }
61
-
62
- sys:: plugin_registry!( pub __GODOT_PLUGIN_REGISTRY: ClassPlugin ) ;
63
-
64
- pub ( crate ) fn iterate_plugins ( mut visitor : impl FnMut ( & ClassPlugin ) ) {
65
- sys:: plugin_foreach!( __GODOT_PLUGIN_REGISTRY; visitor) ;
66
- }
67
-
68
- pub use crate :: obj:: rtti:: ObjectRtti ;
69
-
70
- pub struct ClassConfig {
71
- pub is_tool : bool ,
72
- }
73
-
74
- pub fn is_class_inactive ( is_tool : bool ) -> bool {
75
- if is_tool {
76
- return false ;
77
- }
78
-
79
- // SAFETY: only invoked after global library initialization.
80
- let global_config = unsafe { sys:: config ( ) } ;
81
- let is_editor = || crate :: engine:: Engine :: singleton ( ) . is_editor_hint ( ) ;
82
-
83
- global_config. tool_only_in_editor //.
84
- && global_config. is_editor_or_init ( is_editor)
85
- }
86
-
87
- pub fn print_panic ( err : Box < dyn std:: any:: Any + Send > ) {
88
- if let Some ( s) = err. downcast_ref :: < & ' static str > ( ) {
89
- print_panic_message ( s) ;
90
- } else if let Some ( s) = err. downcast_ref :: < String > ( ) {
91
- print_panic_message ( s. as_str ( ) ) ;
92
- } else {
93
- log:: godot_error!( "Rust panic of type ID {:?}" , err. type_id( ) ) ;
94
- }
95
- }
96
-
97
- pub fn auto_init < T > ( l : & mut crate :: obj:: OnReady < T > ) {
98
- l. init_auto ( ) ;
99
- }
100
-
101
- fn print_panic_message ( msg : & str ) {
102
- // If the message contains newlines, print all of the lines after a line break, and indent them.
103
- let lbegin = "\n " ;
104
- let indented = msg. replace ( '\n' , lbegin) ;
105
-
106
- if indented. len ( ) != msg. len ( ) {
107
- log:: godot_error!( "Panic msg:{lbegin}{indented}" ) ;
108
- } else {
109
- log:: godot_error!( "Panic msg: {msg}" ) ;
110
- }
111
- }
112
-
113
- struct GodotPanicInfo {
114
- line : u32 ,
115
- file : String ,
116
- //backtrace: Backtrace, // for future use
117
- }
118
-
119
- /// Executes `code`. If a panic is thrown, it is caught and an error message is printed to Godot.
120
- ///
121
- /// Returns `None` if a panic occurred, and `Some(result)` with the result of `code` otherwise.
122
- #[ must_use]
123
- pub fn handle_panic < E , F , R , S > ( error_context : E , code : F ) -> Option < R >
124
- where
125
- E : FnOnce ( ) -> S ,
126
- F : FnOnce ( ) -> R + std:: panic:: UnwindSafe ,
127
- S : std:: fmt:: Display ,
128
- {
129
- let info: Arc < Mutex < Option < GodotPanicInfo > > > = Arc :: new ( Mutex :: new ( None ) ) ;
130
-
131
- // Back up previous hook, set new one
132
- let prev_hook = std:: panic:: take_hook ( ) ;
133
- {
134
- let info = info. clone ( ) ;
135
- std:: panic:: set_hook ( Box :: new ( move |panic_info| {
136
- if let Some ( location) = panic_info. location ( ) {
137
- * info. lock ( ) . unwrap ( ) = Some ( GodotPanicInfo {
138
- file : location. file ( ) . to_string ( ) ,
139
- line : location. line ( ) ,
140
- //backtrace: Backtrace::capture(),
141
- } ) ;
142
- } else {
143
- println ! ( "panic occurred but can't get location information..." ) ;
144
- }
145
- } ) ) ;
146
- }
147
-
148
- // Run code that should panic, restore hook
149
- let panic = std:: panic:: catch_unwind ( code) ;
150
- std:: panic:: set_hook ( prev_hook) ;
151
-
152
- match panic {
153
- Ok ( result) => Some ( result) ,
154
- Err ( err) => {
155
- // Flush, to make sure previous Rust output (e.g. test announcement, or debug prints during app) have been printed
156
- // TODO write custom panic handler and move this there, before panic backtrace printing
157
- flush_stdout ( ) ;
158
-
159
- let guard = info. lock ( ) . unwrap ( ) ;
160
- let info = guard. as_ref ( ) . expect ( "no panic info available" ) ;
161
- log:: godot_error!(
162
- "Rust function panicked in file {} at line {}. Context: {}" ,
163
- info. file,
164
- info. line,
165
- error_context( )
166
- ) ;
167
- //eprintln!("Backtrace:\n{}", info.backtrace);
168
- print_panic ( err) ;
169
- None
170
- }
171
- }
172
- }
173
-
174
- pub fn flush_stdout ( ) {
175
- use std:: io:: Write ;
176
- std:: io:: stdout ( ) . flush ( ) . expect ( "flush stdout" ) ;
177
- }
178
-
179
- /// Ensure `T` is an editor plugin.
180
- pub const fn is_editor_plugin < T : crate :: obj:: Inherits < crate :: engine:: EditorPlugin > > ( ) { }
181
-
182
- // ------------------------------------------------------------------------------------------------------------------------------------------
183
- // Compatibility
184
-
185
- // Code generated by Rust derive macros cannot cause any deprecation warnings, due to questionable "feature"
186
- // https://github.com/rust-lang/rust/pull/58994. Fortunately, an extra layer of indirection solves most problems: we generate a declarative
187
- // macro that itself isn't deprecated, but _its_ expansion is. Since the expansion happens in a later step, the warning is emitted.
188
-
189
- #[ inline( always) ]
190
- #[ deprecated = "#[base] is no longer needed; Base<T> is recognized directly. \n \
191
- More information on https://github.com/godot-rust/gdext/pull/577."]
192
- pub const fn base_attribute ( ) { }
193
-
194
- #[ doc( hidden) ]
195
- #[ macro_export]
196
- macro_rules! __emit_deprecated_warning {
197
- ( $warning_fn: ident) => {
198
- const _: ( ) = $crate:: private:: $warning_fn( ) ;
199
- } ;
200
- }
201
-
202
- pub use crate :: __emit_deprecated_warning;
203
- }
204
53
205
54
macro_rules! generate_gdextension_api_version {
206
55
(
0 commit comments