use lua::{Index, ToLua, FromLua, State};
use types::LuaStackable;
use context::Context;
pub struct LuaThread {
index: Index
}
impl LuaThread {
pub fn new(i: Index) -> LuaThread {
LuaThread {
index: i
}
}
pub fn as_state(&self, context: &mut Context) -> State {
context.get_state().to_thread(self.index).unwrap()
}
}
impl LuaStackable for LuaThread {
fn get_pos(&self) -> Index {
self.index
}
}
impl ToLua for LuaThread {
fn to_lua(&self, state: &mut State) {
state.push_value(self.get_pos());
}
}
impl FromLua for LuaThread {
fn from_lua(state: &mut State, index: Index) -> Option<LuaThread> {
if state.is_thread(index) {
Some(LuaThread::new(index))
} else {
None
}
}
}