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
pub use obs_sys;

pub mod context;
pub mod module;
pub mod source;
pub mod graphics;

pub use context::ModuleContext;
pub use module::*;
pub use source::context::ActiveContext;

pub mod string {
    pub struct ObsString(&'static str);

    impl ObsString {
        pub unsafe fn from_str(string: &'static str) -> Self {
            Self(string)
        }

        pub fn as_str(&self) -> &'static str {
            self.0
        }

        pub fn as_ptr(&self) -> *const std::os::raw::c_char {
            self.0.as_ptr() as *const std::os::raw::c_char
        }
    }

    #[macro_export]
    macro_rules! obs_string {
        ($e:expr) => {
            unsafe { $crate::ObsString::from_str(concat!($e, "\0")) }
        };
    }
}

mod log {
    #[macro_export]
    macro_rules! obs_log {
        ($level:expr, $($arg:tt)*) => (unsafe {
            $crate::obs_sys::blog($level, format!("{}", format_args!($($arg)*)).as_ptr() as *const std::os::raw::c_char)
        });
    }

    #[macro_export]
    macro_rules! debug {
        ($($arg:tt)*) => ($crate::obs_log!(400, $($arg)*));
    }

    #[macro_export]
    macro_rules! info {
        ($($arg:tt)*) => ($crate::obs_log!(300, $($arg)*));
    }

    #[macro_export]
    macro_rules! warning {
        ($($arg:tt)*) => ($crate::obs_log!(200, $($arg)*));
    }

    #[macro_export]
    macro_rules! error {
        ($($arg:tt)*) => ($crate::obs_log!(100, $($arg)*));
    }
}

pub use log::*;
pub use string::*;