summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Orlenko <zxteam@protonmail.com>2021-06-13 23:28:41 +0100
committerAlex Orlenko <zxteam@protonmail.com>2021-06-13 23:30:56 +0100
commitfca21d56d38fd0ee394114074d980bdf7e06ff7f (patch)
treedc9c628c72bdfce4e96336cdbbab15d1f3f40718
parent6e52bb7e651e7cbc55d915a4994b0f232c2966c2 (diff)
downloadmlua-fca21d56d38fd0ee394114074d980bdf7e06ff7f.zip
Check stack in entrypoint1 before pushing value to a stack
-rw-r--r--src/lua.rs20
1 files 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<R>,
{
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)
}