pub struct Function<'lua>(_);
Expand description

Handle to an internal Lua function.

Implementations

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);

Returns a future 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?;

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);

Returns information about the function.

Corresponds to the >Sn what mask for lua_getinfo when applied to the function.

Retrieves recorded coverage information about this Lua function including inner calls.

This function takes a callback as an argument and calls it providing CoverageInfo snapshot per each executed inner function.

Recording of coverage information is controlled by Compiler::set_coverage_level option.

Requires feature = "luau"

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Performs the conversion.
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.