From 8ca286f26c90bacfc02d5678cafefc1cf66fcd46 Mon Sep 17 00:00:00 2001 From: Terence Date: Thu, 15 Mar 2018 17:43:44 -0400 Subject: [PATCH] don't panic on failing to LuaRead a Vec --- hlua/src/rust_tables.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/hlua/src/rust_tables.rs b/hlua/src/rust_tables.rs index ffcf3adb..2aac749b 100755 --- a/hlua/src/rust_tables.rs +++ b/hlua/src/rust_tables.rs @@ -133,8 +133,18 @@ impl<'lua, L, V> LuaRead for Vec } }; - let value: V = - LuaRead::lua_read_at_position(&mut me, -1).ok().unwrap(); + let value = { + let maybe_value: Option = + 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) };