#![deny(trivial_casts)]
extern crate xplm_sys;
use std::ffi::CString;
mod ffi;
mod paths;
mod plugin_macro;
mod internal;
pub mod command;
pub mod data;
pub mod draw;
pub mod error;
pub mod feature;
pub mod flight_loop;
pub mod geometry;
pub mod menu;
pub mod plugin;
pub mod versions;
pub mod window;
#[deprecated(note = "Please use the debug! or debugln! macro instead")]
pub fn debug<S: Into<String>>(message: S) {
match CString::new(message.into()) {
Ok(message_c) => unsafe { XPLMDebugString(message_c.as_ptr()) },
Err(_) => unsafe {
XPLMDebugString("[xplm] Invalid debug message\n\0".as_ptr() as *const _)
},
}
}
#[doc(hidden)]
pub use xplm_sys::XPLMDebugString;
#[macro_export]
macro_rules! debug {
($($arg:tt)*) => ({
let formatted_string: String = std::fmt::format(std::format_args!($($arg)*));
#[allow(unused_unsafe)] match std::ffi::CString::new(formatted_string) {
Ok(c_str) => unsafe { $crate::XPLMDebugString(c_str.as_ptr()) },
Err(_) => unsafe { $crate::XPLMDebugString("[xplm] Invalid debug message\n\0".as_ptr() as *const _) }
}
});
}
#[macro_export]
#[allow(unused_unsafe)]
macro_rules! debugln {
() => ($crate::debug!("\n"));
($($arg:tt)*) => ({
let mut formatted_string: String = std::fmt::format(std::format_args!($($arg)*));
formatted_string.push_str("\n");
#[allow(unused_unsafe)] match std::ffi::CString::new(formatted_string) {
Ok(c_str) => unsafe { $crate::XPLMDebugString(c_str.as_ptr()) },
Err(_) => unsafe { $crate::XPLMDebugString("[xplm] Invalid debug message\n\0".as_ptr() as *const _) }
}
});
}
pub fn find_symbol<S: Into<String>>(name: S) -> *mut std::os::raw::c_void {
use std::ptr;
match std::ffi::CString::new(name.into()) {
Ok(name_c) => unsafe { xplm_sys::XPLMFindSymbol(name_c.as_ptr()) },
Err(_) => ptr::null_mut(),
}
}
pub fn speak<S: Into<String>>(msg: S) {
match std::ffi::CString::new(msg.into()) {
Ok(msg) => unsafe {
xplm_sys::XPLMSpeakString(msg.as_ptr());
},
Err(_) => unsafe {
crate::XPLMDebugString("[xplm] Invalid speak message\n\0".as_ptr() as *const _)
},
}
}