pub struct Function { /* private fields */ }Expand description
A handle to a callable Lua value (a Lua closure or a Rust function).
Mirrors mlua::Function. Under the send feature it is Send but never
Sync — see [crate::sync::NotSync].
Implementations§
Source§impl Function
impl Function
Sourcepub fn call<R: FromLuaMulti>(&self, args: impl IntoLuaMulti) -> Result<R>
pub fn call<R: FromLuaMulti>(&self, args: impl IntoLuaMulti) -> Result<R>
Call the function with args, converting the results to R.
Mirrors mlua::Function::call. Runs under lua_pcall, so a Lua runtime
error (or a Rust callback returning Err) becomes Err(Error) rather
than unwinding.
Sourcepub fn bind(&self, args: impl IntoLuaMulti) -> Result<Function>
pub fn bind(&self, args: impl IntoLuaMulti) -> Result<Function>
Return a new function that, when called, prepends args to its own
arguments and forwards to self.
Mirrors mlua::Function::bind. Implemented as a Rust closure that
captures the bound prefix and the target function.
Sourcepub fn wrap<F, A, R, E>(func: F) -> impl IntoLuawhere
F: LuaNativeFn<A, Output = Result<R, E>> + MaybeSend + 'static,
A: FromLuaMulti,
R: IntoLuaMulti,
E: ExternalError,
pub fn wrap<F, A, R, E>(func: F) -> impl IntoLuawhere
F: LuaNativeFn<A, Output = Result<R, E>> + MaybeSend + 'static,
A: FromLuaMulti,
R: IntoLuaMulti,
E: ExternalError,
Wrap a plain Rust closure as a value convertible into a Lua function.
Mirrors mlua::Function::wrap. Unlike
Lua::create_function, the closure does
not receive the Lua and its arity is free (||, |a|, |a, b|,
… mapped from the Lua call arguments). The returned value is
IntoLua so it can be stored directly (e.g.
table.set("f", Function::wrap(|a, b| Ok::<_, Error>(a + b)))). A
returned Err is raised as a Lua error.
Sourcepub fn to_pointer(&self) -> *const c_void
pub fn to_pointer(&self) -> *const c_void
A raw pointer identifying this function (for identity comparison).
Mirrors mlua::Function::to_pointer.
Sourcepub fn environment(&self) -> Option<Table>
pub fn environment(&self) -> Option<Table>
The function’s environment table (its globals), or None for a Rust
(C) function. Mirrors mlua::Function::environment.
Sourcepub fn set_environment(&self, env: Table) -> Result<bool>
pub fn set_environment(&self, env: Table) -> Result<bool>
Set the function’s environment table. Returns Ok(false) for a Rust
(C) function (which has no settable environment) and Ok(true) for a
Lua closure. Mirrors mlua::Function::set_environment.
Sourcepub fn info(&self) -> FunctionInfo
pub fn info(&self) -> FunctionInfo
Debug information about this function. Mirrors mlua::Function::info.
Trait Implementations§
Source§impl FromLua for Function
impl FromLua for Function
Source§fn from_lua_arg(
arg: Value,
_i: usize,
_to: Option<&str>,
lua: &Lua,
) -> Result<Self>
fn from_lua_arg( arg: Value, _i: usize, _to: Option<&str>, lua: &Lua, ) -> Result<Self>
i. The default forwards to
FromLua::from_lua; specific impls can produce nicer messages.
Mirrors mlua::FromLua::from_lua_arg.