pub fn create_function<'lua, A, R, F>(&'lua self, func: F) -> Result<Function<'lua>>
    where
        A: FromLuaMulti<'lua>,
        R: ToLuaMulti<'lua>,
        F: 'static + MaybeSend + Fn(&'lua Lua, A) -> Result<R>,
    {
        self.create_callback(Box::new(move |lua, args| {
            func(lua, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua)
        }))
    }
/// Wraps a Rust function or closure, creating a callable Lua function handle to it.
///
/// The function's return value is always a `Result`: If the function returns `Err`, the error
/// is raised as a Lua error, which can be caught using `(x)pcall` or bubble up to the Rust code
/// that invoked the Lua code. This allows using the `?` operator to propagate errors through
/// intermediate Lua code.
///
/// If the function returns `Ok`, the contained value will be converted to one or more Lua
/// values. For details on Rust-to-Lua conversions, refer to the [`ToLua`] and [`ToLuaMulti`]
/// traits.
///
/// # Examples
///
/// Create a function which prints its argument:
///
/// ```
/// # use mlua::{Lua, Result};
/// # fn main() -> Result<()> {
/// # let lua = Lua::new();
/// let greet = lua.create_function(|_, name: String| {
///     println!("Hello, {}!", name);
///     Ok(())
/// });
/// # let _ = greet;    // used
/// # Ok(())
/// # }
/// ```
///
/// Use tuples to accept multiple arguments:
///
/// ```
/// # use mlua::{Lua, Result};
/// # fn main() -> Result<()> {
/// # let lua = Lua::new();
/// let print_person = lua.create_function(|_, (name, age): (String, u8)| {
///     println!("{} is {} years old!", name, age);
///     Ok(())
/// });
/// # let _ = print_person;    // used
/// # Ok(())
/// # }
/// ```
///
/// [`ToLua`]: crate::ToLua
/// [`ToLuaMulti`]: crate::ToLuaMulti
Wraps a Rust function or closure, creating a callable Lua function handle to it.

If the function returns `Ok`, the contained value will be converted to one or more Lua
values. For details on Rust-to-Lua conversions, refer to the [`ToLua`] and [`ToLuaMulti`]
traits.
Wraps a Rust function or closure creating a callable Lua function handle to it . If the function returns ` Ok ` the contained value will be converted to one or more Lua values . For details on Rust - to - Lua conversions refer to the [ ` ToLua ` ] and [ ` ToLuaMulti ` ] traits .
pub fn create_function<'lua, A, R, F>(&'lua self, func: F) -> Result<Function<'lua>>
    where
        A: FromLuaMulti<'lua>,
        R: ToLuaMulti<'lua>,
        F: 'static + MaybeSend + Fn(&'lua Lua, A) -> Result<R>,
    {
        self.create_callback(Box::new(move |lua, args| {
            func(lua, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua)
        }))
    }
pub fn create_function < ' lua , A , R , F > ( & ' lua self , func : F ) -> Result < Function < ' lua > > where A : FromLuaMulti < ' lua > , R : ToLuaMulti < ' lua > , F : ' static + MaybeSend + Fn ( & ' lua Lua , A ) -> Result < R > , { self . create_callback ( Box :: new ( move | lua , args | { func ( lua , A :: from_lua_multi ( args , lua ) ? ) ? . to_lua_multi ( lua ) } ) ) }
Wraps a Rust function or closure, creating a callable Lua function handle to it.
Wraps a Rust function or closure creating a callable Lua function handle to it .
&'lua self
func
F
&'lua self
func
F
examples
Create a function which prints its argument.


Create a function which prints its argument .
use mlua::{lua, result};
None
fn main() -> result<()> {
None
let lua = lua::new();
let greet = lua.create_function(|_, name: String| {
println!("Hello, {}!", name);
Ok(())
}).
let greet = lua . create_function ( |_ name : String| { println! ( " Hello {} ! " name ) ; Ok (( )) } ) .
let _ = greet;    // used
None
ok(())
None
}


Use tuples to accept multiple arguments.


Use tuples to accept multiple arguments .
use mlua::{lua, result};
None
fn main() -> result<()> {
None
let lua = lua::new();
let print_person = lua.create_function(|_, (name, age): (String, u8)| {
println!("{} is {} years old!", name, age);
Ok(())
}).
let print_person = lua . create_function ( |_ ( name age ) : ( String u8 ) | { println! ( " {} is {} years old! " name age ) ; Ok (( )) } ) .
let _ = print_person;    // used
None
ok(())
None
}


[`ToLua`]: crate::ToLua
[`ToLuaMulti`]: crate::ToLuaMulti
[ ` ToLua ` ] : crate :: ToLua [ ` ToLuaMulti ` ] : crate :: ToLuaMulti