luaext/types/
ltuserdata.rs

1use lua::{Index, ToLua, FromLua, State};
2use types::LuaStackable;
3
4/// Represents a pointer on the Lua stack
5///
6/// Note that you can not retrive the value of light userdata from Lua.
7pub struct LuaLightUserdata {
8    index: Index
9}
10
11impl LuaLightUserdata {
12    /// Create a new LuaLightUserdata at the given index
13    pub fn new(i: Index) -> LuaLightUserdata {
14        LuaLightUserdata {
15            index: i
16        }
17    }
18}
19
20impl LuaStackable for LuaLightUserdata {
21    fn get_pos(&self) -> Index {
22        self.index
23    }
24}
25
26impl ToLua for LuaLightUserdata {
27    fn to_lua(&self, state: &mut State) {
28        state.push_value(self.get_pos());
29    }
30}
31
32impl FromLua for LuaLightUserdata {
33    fn from_lua(state: &mut State, index: Index) -> Option<LuaLightUserdata> {
34        if state.is_light_userdata(index) {
35            Some(LuaLightUserdata::new(index))
36        } else {
37            None
38        }
39    }
40}