pub struct Function<'lua>(_);
Handle to an internal Lua function.
Calls the function, passing args
as function arguments.
The function's return values are converted to the generic type R
.
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);
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
.
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);
Performs copy-assignment from source
. Read more
Formats the value using the given formatter. Read more
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static