pub struct LuaFunction<'lua>(/* private fields */);Expand description
Handle to an internal Lua function.
Implementations§
Source§impl<'lua> Function<'lua>
impl<'lua> Function<'lua>
Sourcepub fn call<A, R>(&self, args: A) -> Result<R, Error>where
A: ToLuaMulti<'lua>,
R: FromLuaMulti<'lua>,
pub fn call<A, R>(&self, args: A) -> Result<R, Error>where
A: ToLuaMulti<'lua>,
R: FromLuaMulti<'lua>,
Calls the function, passing args as function arguments.
The function’s return values are converted to the generic type R.
§Examples
Call Lua’s built-in tostring function:
let globals = lua_context.globals();
let tostring: Function = globals.get("tostring")?;
assert_eq!(tostring.call::<_, String>(123)?, "123");
Call a function with multiple arguments:
let sum: Function = lua_context.load(
r#"
function(a, b)
return a + b
end
"#).eval()?;
assert_eq!(sum.call::<_, u32>((3, 4))?, 3 + 4);
Sourcepub fn bind<A>(&self, args: A) -> Result<Function<'lua>, Error>where
A: ToLuaMulti<'lua>,
pub fn bind<A>(&self, args: A) -> Result<Function<'lua>, Error>where
A: ToLuaMulti<'lua>,
Returns a function that, when called, calls self, passing args as the first set of
arguments.
If any arguments are passed to the returned function, they will be passed after args.
§Examples
let sum: Function = lua_context.load(r#"
function(a, b)
return a + b
end
"#).eval()?;
let bound_a = sum.bind(1)?;
assert_eq!(bound_a.call::<_, u32>(2)?, 1 + 2);
let bound_a_and_b = sum.bind(13)?.bind(57)?;
assert_eq!(bound_a_and_b.call::<_, u32>(())?, 13 + 57);
Trait Implementations§
Auto Trait Implementations§
impl<'lua> !RefUnwindSafe for Function<'lua>
impl<'lua> !Send for Function<'lua>
impl<'lua> !Sync for Function<'lua>
impl<'lua> !UnwindSafe for Function<'lua>
impl<'lua> Freeze for Function<'lua>
impl<'lua> Unpin for Function<'lua>
impl<'lua> UnsafeUnpin for Function<'lua>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Erased for T
Source§impl<'lua, T> FromLuaMulti<'lua> for Twhere
T: FromLua<'lua>,
impl<'lua, T> FromLuaMulti<'lua> for Twhere
T: FromLua<'lua>,
Source§fn from_lua_multi(
values: MultiValue<'lua>,
lua: Context<'lua>,
) -> Result<T, Error>
fn from_lua_multi( values: MultiValue<'lua>, lua: Context<'lua>, ) -> Result<T, Error>
Performs the conversion. Read more
Source§impl<'lua, T> ToLuaMulti<'lua> for Twhere
T: ToLua<'lua>,
impl<'lua, T> ToLuaMulti<'lua> for Twhere
T: ToLua<'lua>,
Source§fn to_lua_multi(self, lua: Context<'lua>) -> Result<MultiValue<'lua>, Error>
fn to_lua_multi(self, lua: Context<'lua>) -> Result<MultiValue<'lua>, Error>
Performs the conversion.