Skip to content

Commit

Permalink
don't panic on failing to LuaRead a Vec
Browse files Browse the repository at this point in the history
  • Loading branch information
Terence committed Mar 15, 2018
1 parent 90b53ae commit 8ca286f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions hlua/src/rust_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,18 @@ impl<'lua, L, V> LuaRead<L> for Vec<V>
}
};

let value: V =
LuaRead::lua_read_at_position(&mut me, -1).ok().unwrap();
let value = {
let maybe_value: Option<V> =
LuaRead::lua_read_at_position(&mut me, -1).ok();
match maybe_value {
None => {
// Cleaning up after ourselves
unsafe { ffi::lua_pop(me.as_mut_lua().0, 2) };
return Err(me)
}
Some(v) => v,
}
};

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

Expand Down

0 comments on commit 8ca286f

Please sign in to comment.