Struct rlua::Function [] [src]

pub struct Function<'lua>(_);

Handle to an internal Lua function.

Methods

impl<'lua> Function<'lua>
[src]

[src]

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 lua = Lua::new();
let globals = lua.globals();

let tostring: Function = globals.get("tostring")?;

assert_eq!(tostring.call::<_, String>(123)?, "123");

Call a function with multiple arguments:

let lua = Lua::new();

let sum: Function = lua.eval(r#"
    function(a, b)
        return a + b
    end
"#, None)?;

assert_eq!(sum.call::<_, u32>((3, 4))?, 3 + 4);

[src]

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 lua = Lua::new();

let sum: Function = lua.eval(r#"
    function(a, b)
        return a + b
    end
"#, None)?;

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

impl<'lua> ToLua<'lua> for Function<'lua>
[src]

[src]

Performs the conversion.

impl<'lua> FromLua<'lua> for Function<'lua>
[src]

[src]

Performs the conversion.

impl<'lua> Clone for Function<'lua>
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<'lua> Debug for Function<'lua>
[src]

[src]

Formats the value using the given formatter.