summaryrefslogtreecommitdiff
path: root/src/macros.rs
blob: 13130ac43930c019180e1b34e96408b66c8215df (plain)
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
macro_rules! cstr {
  ($s:expr) => (
    concat!($s, "\0") as *const str as *const [c_char] as *const c_char
  );
}

// A panic that clears the given lua stack before panicking
macro_rules! lua_panic {
    ($state:expr) => {
        {
            $crate::ffi::lua_settor($state, 0);
            panic!("rlua internal error");
        }
    };

    ($state:expr, $msg:expr) => {
        {
            $crate::ffi::lua_settop($state, 0);
            panic!(concat!("rlua: ", $msg));
        }
    };

    ($state:expr, $fmt:expr, $($arg:tt)+) => {
        {
            $crate::ffi::lua_settop($state, 0);
            panic!(concat!("rlua: ", $fmt), $($arg)+);
        }
    };
}

// An assert that clears the given lua stack before panicking
macro_rules! lua_assert {
    ($state:expr, $cond:expr) => {
        if !$cond {
            $crate::ffi::lua_settop($state, 0);
            panic!("rlua internal error");
        }
    };

    ($state:expr, $cond:expr, $msg:expr) => {
        if !$cond {
            $crate::ffi::lua_settop($state, 0);
            panic!(concat!("rlua: ", $msg));
        }
    };

    ($state:expr, $cond:expr, $fmt:expr, $($arg:tt)+) => {
        if !$cond {
            $crate::ffi::lua_settop($state, 0);
            panic!(concat!("rlua: ", $fmt), $($arg)+);
        }
    };
}