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
use lua::{Index, Type, ToLua, FromLua, State};
use types::{LuaStackable};
use context::Context;
pub struct LuaGeneric {
index: Index
}
impl LuaGeneric {
pub fn new(i: Index) -> LuaGeneric {
LuaGeneric {
index: i
}
}
pub fn type_of(&self, context: &mut Context) -> Type {
context.get_state().type_of(self.index).unwrap()
}
pub fn get_value<T: FromLua>(&self, context: &mut Context) -> Option<T> {
context.get_state().to_type(self.index)
}
}
impl LuaStackable for LuaGeneric {
fn get_pos(&self) -> Index {
self.index
}
}
impl ToLua for LuaGeneric {
fn to_lua(&self, state: &mut State) {
state.push_value(self.get_pos());
}
}
impl FromLua for LuaGeneric {
fn from_lua(_: &mut State, index: Index) -> Option<LuaGeneric> {
Some(LuaGeneric::new(index))
}
}