From fca21d56d38fd0ee394114074d980bdf7e06ff7f Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Sun, 13 Jun 2021 23:28:41 +0100 Subject: [PATCH] Check stack in entrypoint1 before pushing value to a stack --- src/lua.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/lua.rs b/src/lua.rs index a9f6b5b..6b50be8 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -536,14 +536,18 @@ impl Lua { F: 'static + MaybeSend + Fn(&'callback Lua) -> Result, { let cb = self.create_callback(Box::new(move |lua, _| func(lua)?.to_lua_multi(lua)))?; - match cb.call(()) { - Ok(res) => unsafe { self.push_value(res)? }, - Err(err) => unsafe { - self.push_value(Value::Error(err))?; - // This longjmp is undesired, but we cannot wrap it to a C - ffi::lua_error(self.state) - }, - } + let res = cb.call(()); + unsafe { + check_stack(self.state, 2)?; + match res { + Ok(res) => self.push_value(res)?, + Err(err) => { + self.push_value(Value::Error(err))?; + // This longjmp is undesired, but we cannot wrap it to a C + ffi::lua_error(self.state) + } + } + }; Ok(1) }