pub fn call<A: ToLuaMulti<'lua>, R: FromLuaMulti<'lua>>(&self, args: A) -> Result<R> {
        let lua = self.0.lua;

        let mut args = args.to_lua_multi(lua)?;
        let nargs = args.len() as c_int;

        let results = unsafe {
            let _sg = StackGuard::new(lua.state);
            check_stack(lua.state, nargs + 3)?;

            ffi::lua_pushcfunction(lua.state, error_traceback);
            let stack_start = ffi::lua_gettop(lua.state);
            lua.push_ref(&self.0);
            for arg in args.drain_all() {
                lua.push_value(arg)?;
            }
            let ret = ffi::lua_pcall(lua.state, nargs, ffi::LUA_MULTRET, stack_start);
            if ret != ffi::LUA_OK {
                return Err(pop_error(lua.state, ret));
            }
            let nresults = ffi::lua_gettop(lua.state) - stack_start;
            let mut results = args; // Reuse MultiValue container
            assert_stack(lua.state, 2);
            for _ in 0..nresults {
                results.push_front(lua.pop_value());
            }
            ffi::lua_pop(lua.state, 1);
            results
        };
        R::from_lua_multi(results, lua)
    }
/// 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:
///
/// ```
/// # use mlua::{Function, Lua, Result};
/// # fn main() -> Result<()> {
/// # let lua = Lua::new();
/// let globals = lua.globals();
///
/// let tostring: Function = globals.get("tostring")?;
///
/// assert_eq!(tostring.call::<_, String>(123)?, "123");
///
/// # Ok(())
/// # }
/// ```
///
/// Call a function with multiple arguments:
///
/// ```
/// # use mlua::{Function, Lua, Result};
/// # fn main() -> Result<()> {
/// # let lua = Lua::new();
/// let sum: Function = lua.load(
///     r#"
///         function(a, b)
///             return a + b
///         end
/// "#).eval()?;
///
/// assert_eq!(sum.call::<_, u32>((3, 4))?, 3 + 4);
///
/// # Ok(())
/// # }
/// ```
Calls the function, passing `args` as function arguments.
The function's return values are converted to the generic type `R`.
Calls the function passing ` args ` as function arguments . The function ' s return values are converted to the generic type ` R ` .
pub fn call<A: ToLuaMulti<'lua>, R: FromLuaMulti<'lua>>(&self, args: A) -> Result<R> {
        let lua = self.0.lua;
        let mut args = args.to_lua_multi(lua)?;
        let nargs = args.len() as c_int;
        let results = unsafe {
            let _sg = StackGuard::new(lua.state);
            check_stack(lua.state, nargs + 3)?;
            ffi::lua_pushcfunction(lua.state, error_traceback);
            let stack_start = ffi::lua_gettop(lua.state);
            lua.push_ref(&self.0);
            for arg in args.drain_all() {
                lua.push_value(arg)?;
            }
            let ret = ffi::lua_pcall(lua.state, nargs, ffi::LUA_MULTRET, stack_start);
            if ret != ffi::LUA_OK {
                return Err(pop_error(lua.state, ret));
            }
            let nresults = ffi::lua_gettop(lua.state) - stack_start;
            let mut results = args; // Reuse MultiValue container
            assert_stack(lua.state, 2);
            for _ in 0..nresults {
                results.push_front(lua.pop_value());
            }
            ffi::lua_pop(lua.state, 1);
            results
        };
        R::from_lua_multi(results, lua)
    }
pub fn call < A : ToLuaMulti < ' lua > , R : FromLuaMulti < ' lua > > ( & self , args : A ) -> Result < R > { let lua = self . 0 . lua ; let mut args = args . to_lua_multi ( lua ) ? ; let nargs = args . len ( ) as c_int ; let results = unsafe { let _sg = StackGuard :: new ( lua . state ) ; check_stack ( lua . state , nargs + 3 ) ? ; ffi :: lua_pushcfunction ( lua . state , error_traceback ) ; let stack_start = ffi :: lua_gettop ( lua . state ) ; lua . push_ref ( & self . 0 ) ; for arg in args . drain_all ( ) { lua . push_value ( arg ) ? ; } let ret = ffi :: lua_pcall ( lua . state , nargs , ffi :: LUA_MULTRET , stack_start ) ; if ret != ffi :: LUA_OK { return Err ( pop_error ( lua . state , ret ) ) ; } let nresults = ffi :: lua_gettop ( lua . state ) - stack_start ; let mut results = args ; // Reuse MultiValue container assert_stack ( lua . state , 2 ) ; for _ in 0 .. nresults { results . push_front ( lua . pop_value ( ) ) ; } ffi :: lua_pop ( lua . state , 1 ) ; results } ; R :: from_lua_multi ( results , lua ) }
Calls the function, passing `args` as function arguments.
Calls the function passing ` args ` as function arguments .
&self
args
A
&self
args
A
examples
Call Lua's built-in `tostring` function.


Call Lua ' s built - in ` tostring ` function .
use mlua::{function, lua, result};
None
fn main() -> result<()> {
None
let lua = lua::new();
let globals = lua.globals().

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


let globals = lua . globals () . let tostring : Function = globals . get ( " tostring " ) ? .
ok(())
None
}


Call a function with multiple arguments.


Call a function with multiple arguments .
use mlua::{function, lua, result};
None
fn main() -> result<()> {
None
let lua = lua::new();
let sum: Function = lua.load(
r#"
function(a, b)
return a + b
end
"#).eval()?.


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