gdnative_core/init/
info.rs1use crate::core_types::GodotString;
2
3pub struct InitializeInfo {
5 in_editor: bool,
6 active_library_path: GodotString,
7 options: *mut crate::sys::godot_gdnative_init_options,
8}
9
10impl InitializeInfo {
11 #[inline]
13 pub fn in_editor(&self) -> bool {
14 self.in_editor
15 }
16
17 #[inline]
21 pub fn active_library_path(&self) -> &GodotString {
22 &self.active_library_path
23 }
24
25 #[inline]
31 #[doc(hidden)]
32 pub unsafe fn new(options: *mut crate::sys::godot_gdnative_init_options) -> Self {
33 assert!(!options.is_null(), "options were NULL");
34 let crate::sys::godot_gdnative_init_options {
35 in_editor,
36 active_library_path,
37 ..
38 } = *options;
39
40 let active_library_path = GodotString::clone_from_sys(*active_library_path);
41
42 Self {
43 in_editor,
44 active_library_path,
45 options,
46 }
47 }
48
49 #[inline]
50 pub fn report_loading_error<T>(&self, message: T)
51 where
52 T: std::fmt::Display,
53 {
54 let crate::sys::godot_gdnative_init_options {
55 report_loading_error,
56 gd_native_library,
57 ..
58 } = unsafe { *self.options };
59
60 if let Some(report_loading_error_fn) = report_loading_error {
61 let message = format!("{message}\0");
63
64 let message = std::ffi::CStr::from_bytes_with_nul(message.as_bytes())
66 .expect("message should not have a NULL");
67
68 unsafe {
69 report_loading_error_fn(gd_native_library, message.as_ptr());
70 }
71 }
72 }
73}
74
75pub struct TerminateInfo {
77 in_editor: bool,
78}
79
80impl TerminateInfo {
81 #[inline]
82 #[doc(hidden)] pub unsafe fn new(options: *mut crate::sys::godot_gdnative_terminate_options) -> Self {
84 assert!(!options.is_null(), "options were NULL");
85
86 let crate::sys::godot_gdnative_terminate_options { in_editor } = *options;
87
88 Self { in_editor }
89 }
90
91 #[inline]
93 pub fn in_editor(&self) -> bool {
94 self.in_editor
95 }
96}