Struct Function
pub struct Function(pub(crate) ValueRef);Expand description
Handle to an internal Lua function.
Tuple Fields§
§0: ValueRefImplementations§
§impl Function
impl Function
pub fn call<R>(&self, args: impl IntoLuaMulti) -> Result<R, Error>where
R: FromLuaMulti,
pub fn call<R>(&self, args: impl IntoLuaMulti) -> Result<R, Error>where
R: FromLuaMulti,
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);
pub fn bind(&self, args: impl IntoLuaMulti) -> Result<Function, Error>
pub fn bind(&self, args: impl IntoLuaMulti) -> Result<Function, Error>
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);
pub fn environment(&self) -> Option<Table>
pub fn environment(&self) -> Option<Table>
Returns the environment of the Lua function.
By default Lua functions shares a global environment.
This function always returns None for Rust/C functions.
pub fn set_environment(&self, env: Table) -> Result<bool, Error>
pub fn set_environment(&self, env: Table) -> Result<bool, Error>
Sets the environment of the Lua function.
The environment is a table that is used as the global environment for the function.
Returns true if environment successfully changed, false otherwise.
This function does nothing for Rust/C functions.
pub fn info(&self) -> FunctionInfo
pub fn info(&self) -> FunctionInfo
Returns information about the function.
Corresponds to the >Sn what mask for lua_getinfo when applied to the function.
pub fn dump(&self, strip: bool) -> Vec<u8> ⓘ
pub fn dump(&self, strip: bool) -> Vec<u8> ⓘ
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.
For Luau a Compiler can be used to compile Lua chunks to bytecode.
pub fn to_pointer(&self) -> *const c_void
pub fn to_pointer(&self) -> *const c_void
Converts this function to a generic C pointer.
There is no way to convert the pointer back to its original value.
Typically this function is used only for hashing and debug information.
§impl Function
impl Function
pub fn wrap<F, A, R>(func: F) -> impl IntoLuawhere
F: LuaNativeFn<A, Output = Result<R, Error>> + MaybeSend + 'static,
A: FromLuaMulti,
R: IntoLuaMulti,
pub fn wrap<F, A, R>(func: F) -> impl IntoLuawhere
F: LuaNativeFn<A, Output = Result<R, Error>> + MaybeSend + 'static,
A: FromLuaMulti,
R: IntoLuaMulti,
Wraps a Rust function or closure, returning an opaque type that implements IntoLua
trait.
pub fn wrap_mut<F, A, R>(func: F) -> impl IntoLuawhere
F: LuaNativeFnMut<A, Output = Result<R, Error>> + MaybeSend + 'static,
A: FromLuaMulti,
R: IntoLuaMulti,
pub fn wrap_mut<F, A, R>(func: F) -> impl IntoLuawhere
F: LuaNativeFnMut<A, Output = Result<R, Error>> + MaybeSend + 'static,
A: FromLuaMulti,
R: IntoLuaMulti,
Wraps a Rust mutable closure, returning an opaque type that implements IntoLua trait.
pub fn wrap_raw<F, A>(func: F) -> impl IntoLua
pub fn wrap_raw<F, A>(func: F) -> impl IntoLua
Wraps a Rust function or closure, returning an opaque type that implements IntoLua
trait.
This function is similar to Function::wrap but any returned Result will be converted
to a ok, err tuple without throwing an exception.
pub fn wrap_raw_mut<F, A>(func: F) -> impl IntoLua
pub fn wrap_raw_mut<F, A>(func: F) -> impl IntoLua
Wraps a Rust mutable closure, returning an opaque type that implements IntoLua trait.
This function is similar to Function::wrap_mut but any returned Result will be
converted to a ok, err tuple without throwing an exception.
Trait Implementations§
impl StructuralPartialEq for Function
Auto Trait Implementations§
impl Freeze for Function
impl !RefUnwindSafe for Function
impl !Send for Function
impl !Sync for Function
impl Unpin for Function
impl !UnwindSafe for Function
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FromLuaMulti for Twhere
T: FromLua,
impl<T> FromLuaMulti for Twhere
T: FromLua,
§fn from_lua_multi(values: MultiValue, lua: &Lua) -> Result<T, Error>
fn from_lua_multi(values: MultiValue, lua: &Lua) -> Result<T, Error>
fn from_lua_args( args: MultiValue, i: usize, to: Option<&str>, lua: &Lua, ) -> Result<T, Error>
unsafe fn from_stack_multi(nvals: i32, lua: &RawLua) -> Result<T, Error>
unsafe fn from_stack_args( nargs: i32, i: usize, to: Option<&str>, lua: &RawLua, ) -> Result<T, Error>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoLuaMulti for Twhere
T: IntoLua,
impl<T> IntoLuaMulti for Twhere
T: IntoLua,
§fn into_lua_multi(self, lua: &Lua) -> Result<MultiValue, Error>
fn into_lua_multi(self, lua: &Lua) -> Result<MultiValue, Error>
unsafe fn push_into_stack_multi(self, lua: &RawLua) -> Result<i32, Error>
§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
§type Error = Infallible
type Error = Infallible
Result.§fn into_result(self) -> Result<T, <T as IntoResult<T>>::Error>
fn into_result(self) -> Result<T, <T as IntoResult<T>>::Error>
Result.§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg] or
a color-specific method, such as [OwoColorize::green], Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg] or
a color-specific method, such as [OwoColorize::on_yellow], Read more