Skip to main content

Function

Struct Function 

Source
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

Source

pub fn lua(&self) -> Lua

The owning Lua.

Source

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.

Source

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.

Source

pub fn wrap<F, A, R, E>(func: F) -> impl IntoLua
where 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.

Source

pub fn to_pointer(&self) -> *const c_void

A raw pointer identifying this function (for identity comparison). Mirrors mlua::Function::to_pointer.

Source

pub fn environment(&self) -> Option<Table>

The function’s environment table (its globals), or None for a Rust (C) function. Mirrors mlua::Function::environment.

Source

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.

Source

pub fn info(&self) -> FunctionInfo

Debug information about this function. Mirrors mlua::Function::info.

Trait Implementations§

Source§

impl Clone for Function

Source§

fn clone(&self) -> Function

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Function

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromLua for Function

Source§

fn from_lua(value: Value, _lua: &Lua) -> Result<Self>

Perform the conversion.
Source§

fn from_lua_arg( arg: Value, _i: usize, _to: Option<&str>, lua: &Lua, ) -> Result<Self>

Convert an argument at 1-based position i. The default forwards to FromLua::from_lua; specific impls can produce nicer messages. Mirrors mlua::FromLua::from_lua_arg.
Source§

impl IntoLua for Function

Source§

fn into_lua(self, _lua: &Lua) -> Result<Value>

Perform the conversion.
Source§

impl IntoLua for &Function

Source§

fn into_lua(self, _lua: &Lua) -> Result<Value>

Perform the conversion.
Source§

impl PartialEq for Function

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TypeMetatable for Function

Source§

fn set_type_metatable(lua: &Lua, metatable: Option<Table>)

Install (or clear) the shared metatable for this type.
Source§

fn type_metatable(lua: &Lua) -> Option<Table>

The shared metatable for this type, if installed.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromLuaMulti for T
where T: FromLua,

Source§

fn from_lua_multi(values: MultiValue, lua: &Lua) -> Result<T, Error>

Perform the conversion.
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoLuaMulti for T
where T: IntoLua,

Source§

fn into_lua_multi(self, lua: &Lua) -> Result<MultiValue, Error>

Perform the conversion.
Source§

impl<T> MaybeSend for T

Source§

impl<T> MaybeSync for T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.