mirror of
https://github.com/mlua-rs/mlua
synced 2026-06-08 16:05:43 +00:00
Improve module mode:
- Don't hide module function inside `luaopen_%` function. - Raise Lua exception instead of panic if module function returns error.
This commit is contained in:
+9
-1
@@ -536,7 +536,15 @@ 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)))?;
|
||||
unsafe { self.push_value(cb.call(())?).map(|_| 1) }
|
||||
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)
|
||||
},
|
||||
}
|
||||
Ok(1)
|
||||
}
|
||||
|
||||
/// Sets a 'hook' function that will periodically be called as Lua code executes.
|
||||
|
||||
Reference in New Issue
Block a user