commonlibsse_ng\macros/
console.rs

1//! Skyrim console log print
2
3/// Prints to the in-game console log (Skyrim) without a newline.
4///
5/// This is analogous to [`print!`](https://doc.rust-lang.org/std/macro.print.html),
6/// but targets the Skyrim in-game console log instead of stdout.
7///
8/// # Examples
9///
10/// ```
11/// use commonlibsse_ng::console_print;
12///
13/// console_print!("Hello, {}!", "Dragonborn");
14/// ```
15#[macro_export]
16macro_rules! console_print {
17    ($($arg:tt)*) => {{
18        use ::core::fmt::Write as _;
19        $crate::re::ConsoleLog::print_fmt(format_args!($($arg)*));
20    }};
21}
22
23/// Prints to the in-game console log (Skyrim) with a newline.
24///
25/// This is analogous to [`println!`](https://doc.rust-lang.org/std/macro.println.html),
26/// but targets the Skyrim in-game console log instead of stdout.
27///
28/// # Examples
29///
30/// ```no_run
31/// use commonlibsse_ng::console_println;
32///
33/// console_println!("Level up! You are now level {}", 42);
34/// console_println!(); // just a newline
35/// ```
36///
37/// # Allocate Heap Memory
38/// This uses the [`Write`] trait internally, and since [`str`] is a [`CString`], heap allocation occurs each time it is used.
39///
40/// If the string is fixed at compile time, it is better to use `c""` and `ConsoleLog::print` method to save memory and speed up the process.
41#[macro_export]
42macro_rules! console_println {
43    () => {unsafe {
44        $crate::re::ConsoleLog::ConsoleLog::get_singleton_mut()
45            .map(|console| console.print(c"\n".as_ptr()));
46    }};
47    ($($arg:tt)*) => {{
48        $crate::re::ConsoleLog::print_fmt(format_args!("{}\n", format_args!($($arg)*)));
49    }};
50}