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
use lua::{Index, ToLua, FromLua, State};
use types::{LuaStackable};

/// Represents a nil value on the Lua stack
pub struct LuaNil {
    index: Index
}

impl LuaNil {
    /// Create a new LuaNil given an index
    pub fn new(i: Index) -> LuaNil {
        LuaNil {
            index: i
        }
    }
}

impl LuaStackable for LuaNil {
    fn get_pos(&self) -> Index {
        self.index
    }
}

impl ToLua for LuaNil {
    fn to_lua(&self, state: &mut State) {
        state.push_value(self.get_pos());
    }
}

impl FromLua for LuaNil {
    fn from_lua(state: &mut State, index: Index) -> Option<LuaNil> {
        if state.is_nil(index) {
            Some(LuaNil::new(index))
        } else {
            None
        }
    }
}