commonlibsse_ng\macros/debug_message.rs
1/// Shows a modal message box in-game using Skyrim's `CreateMessage` API.
2///
3/// This macro works similarly to Rust's [`format!`] macro, allowing formatted strings.
4/// Internally, it constructs a `CString` from the formatted string and passes it to [`DebugMessageBox`].
5///
6/// # Example
7///
8/// ```no_run
9/// let x= 0;
10/// let y= 1;
11/// commonlibsse_ng::debug_message_box!("Player position: x = {}, y = {}", x, y);
12/// ```
13///
14/// # Message Box Layout
15/// ```txt
16/// +--------------------------+
17/// | This is a message |
18/// | |
19/// | [OK] | <-- Primary Buttons
20/// +--------------------------+
21/// ```
22///
23/// # Notes
24///
25/// - The string is converted to a C-style string (`CString`), which **must not contain null bytes (`\0`)** in the middle.
26/// If a null byte is present, the message will be replaced with `"Invalid CString"` as a fallback.
27/// - This uses heap allocation under the hood via `CString::new`.
28///
29/// # See also
30/// - [`DebugMessageBox`] for the underlying function.
31/// - [`CString`] for how the formatted string is converted.
32///
33/// # Note
34/// This macro does not panic, but it may silently fail and show a fallback message
35/// if the formatted string contains interior null bytes.
36///
37/// [`DebugMessageBox`]: commonlibsse_ng::re::Misc::DebugMessageBox
38#[macro_export]
39macro_rules! debug_message_box {
40 ($($arg:tt)*) => {{
41 use std::ffi::CString;
42 let formatted = format!($($arg)*);
43 if let Ok(c_string) = CString::new(formatted) {
44 $crate::re::Misc::DebugMessageBox(c_string.as_c_str());
45 } else {
46 $crate::re::Misc::DebugMessageBox(c"[DebugMessageBox Error] <Null byte found in string>");
47 }
48 }};
49}