Skip to content

Commit

Permalink
Implement LuaRead for Vec of any readable type, not just AnyLuaValue.
Browse files Browse the repository at this point in the history
  • Loading branch information
Terence committed Mar 15, 2018
1 parent 84d5ea4 commit 90b53ae
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions hlua/src/rust_tables.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,15 @@ impl<'lua, L, T, E> PushOne<L> for Vec<T>
{
}

impl<'lua, L> LuaRead<L> for Vec<AnyLuaValue>
where L: AsMutLua<'lua>
impl<'lua, L, V> LuaRead<L> for Vec<V>
where L: AsMutLua<'lua>,
V: for<'a> LuaRead<&'a mut L>
{
fn lua_read_at_position(lua: L, index: i32) -> Result<Self, L> {
// We need this as iteration order isn't guaranteed to match order of
// keys, even if they're numeric
// https://www.lua.org/manual/5.2/manual.html#pdf-next
let mut dict: BTreeMap<i32, AnyLuaValue> = BTreeMap::new();
let mut dict: BTreeMap<i32, V> = BTreeMap::new();

let mut me = lua;
unsafe { ffi::lua_pushnil(me.as_mut_lua().0) };
Expand All @@ -132,7 +133,7 @@ impl<'lua, L> LuaRead<L> for Vec<AnyLuaValue>
}
};

let value: AnyLuaValue =
let value: V =
LuaRead::lua_read_at_position(&mut me, -1).ok().unwrap();

unsafe { ffi::lua_pop(me.as_mut_lua().0, 1) };
Expand Down

0 comments on commit 90b53ae

Please sign in to comment.