pub struct Function<'lua>(_);
Expand description
Handle to an internal Lua function.
Implementations
sourceimpl<'lua> Function<'lua>
impl<'lua> Function<'lua>
sourcepub fn call<A: ToLuaMulti<'lua>, R: FromLuaMulti<'lua>>(
&self,
args: A
) -> Result<R>
pub fn call<A: ToLuaMulti<'lua>, R: FromLuaMulti<'lua>>(
&self,
args: A
) -> Result<R>
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.globals();
let tostring: Function = globals.get("tostring")?;
assert_eq!(tostring.call::<_, String>(123)?, "123");
Call a function with multiple arguments:
let sum: Function = lua.load(
r#"
function(a, b)
return a + b
end
"#).eval()?;
assert_eq!(sum.call::<_, u32>((3, 4))?, 3 + 4);
sourcepub fn call_async<'fut, A, R>(&self, args: A) -> LocalBoxFuture<'fut, Result<R>> where
'lua: 'fut,
A: ToLuaMulti<'lua>,
R: FromLuaMulti<'lua> + 'fut,
This is supported on crate feature async
only.
pub fn call_async<'fut, A, R>(&self, args: A) -> LocalBoxFuture<'fut, Result<R>> where
'lua: 'fut,
A: ToLuaMulti<'lua>,
R: FromLuaMulti<'lua> + 'fut,
async
only.Returns a Feature that, when polled, calls self
, passing args
as function arguments,
and drives the execution.
Internally it wraps the function to an AsyncThread
.
Requires feature = "async"
Examples
use std::time::Duration;
use futures_timer::Delay;
let sleep = lua.create_async_function(move |_lua, n: u64| async move {
Delay::new(Duration::from_millis(n)).await;
Ok(())
})?;
sleep.call_async(10).await?;
sourcepub fn bind<A: ToLuaMulti<'lua>>(&self, args: A) -> Result<Function<'lua>>
pub fn bind<A: ToLuaMulti<'lua>>(&self, args: A) -> Result<Function<'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.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);
sourcepub fn dump(&self, strip: bool) -> Vec<u8>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
This is supported on non-crate feature luau
only.
pub fn dump(&self, strip: bool) -> Vec<u8>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
luau
only.Dumps the function as a binary chunk.
If strip
is true, the binary representation may not include all debug information
about the function, to save space.
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> Unpin for Function<'lua>
impl<'lua> !UnwindSafe for Function<'lua>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more