1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
extern crate xplm_sys;
extern crate libc;
pub mod data;
pub mod command;
pub mod flight_loop;
pub mod features;
pub mod terrain;
pub mod position;
pub mod ui;
pub mod nav;
pub mod frequency;
pub mod graphics;
mod ffi;
pub fn debug(message: &str) {
use std::ffi::CString;
use xplm_sys::utilities::XPLMDebugString;
match CString::new(message) {
Ok(message_c) => unsafe { XPLMDebugString(message_c.as_ptr()) },
Err(_) => unsafe { XPLMDebugString(b"xplm::debug: Provided string not valid".as_ptr() as *const i8) },
}
}
pub fn enable_debug_logging() {
unsafe { xplm_sys::utilities::XPLMSetErrorCallback(Some(log_callback)) };
}
unsafe extern "C" fn log_callback(message: *const ::libc::c_char) {
use std::ffi::CStr;
debug(&format!("XPLM error: {}\n", CStr::from_ptr(message).to_string_lossy().into_owned()));
}
pub fn find_symbol(name: &str) -> *mut ::libc::c_void {
use std::ffi::CString;
use std::ptr;
use xplm_sys::utilities::XPLMFindSymbol;
match CString::new(name) {
Ok(name_c) => unsafe { XPLMFindSymbol(name_c.as_ptr()) },
Err(_) => ptr::null_mut(),
}
}