pub fn call<T>(
      &mut self,
      function: Value,
      arguments: impl IntoIterator<Item = Value>,
   ) -> Result<T, Error>
   where
      T: TryFromValue,
   {
      let stack: Vec<_> =
         Some(function).into_iter().chain(arguments).map(|x| x.to_raw(&mut self.gc)).collect();
      // Having to construct a chunk here isn't the most clean, but it's the simplest way of making
      // the VM perform a function call. It reuses sanity checks such as ensuring `function`
      // can actually be called.
      let mut chunk = Chunk::new(Rc::from("(call)"));
      chunk.emit((
         Opcode::Call,
         // 1 has to be subtracted from the stack length there because the VM itself adds 1 to
         // count in the function argument.
         Opr24::try_from(stack.len() - 1).map_err(|_| Error::TooManyArguments)?,
      ));
      chunk.emit(Opcode::Halt);
      let chunk = Rc::new(chunk);
      let fiber = Fiber {
         engine: self,
         inner: vm::Fiber::new(chunk, stack),
      };
      fiber.trampoline()
   }
/// Calls the provided function with the given arguments.
///
/// # Errors
///
/// - [`Error::Runtime`] - if a runtime error occurs - `function` isn't callable or an error is
///   raised during execution
/// - [`Error::TooManyArguments`] - if more arguments than the implementation can support is
///   passed to the function
Calls the provided function with the given arguments.
Calls the provided function with the given arguments .
pub fn call<T>(
      &mut self,
      function: Value,
      arguments: impl IntoIterator<Item = Value>,
   ) -> Result<T, Error>
   where
      T: TryFromValue,
   {
      let stack: Vec<_> =
         Some(function).into_iter().chain(arguments).map(|x| x.to_raw(&mut self.gc)).collect();
      // Having to construct a chunk here isn't the most clean, but it's the simplest way of making
      // the VM perform a function call. It reuses sanity checks such as ensuring `function`
      // can actually be called.
      let mut chunk = Chunk::new(Rc::from("(call)"));
      chunk.emit((
         Opcode::Call,
         // 1 has to be subtracted from the stack length there because the VM itself adds 1 to
         // count in the function argument.
         Opr24::try_from(stack.len() - 1).map_err(|_| Error::TooManyArguments)?,
      ));
      chunk.emit(Opcode::Halt);
      let chunk = Rc::new(chunk);
      let fiber = Fiber {
         engine: self,
         inner: vm::Fiber::new(chunk, stack),
      };
      fiber.trampoline()
   }
pub fn call < T > ( & mut self , function : Value , arguments : impl IntoIterator < Item = Value > , ) -> Result < T , Error > where T : TryFromValue , { let stack : Vec < _ > = Some ( function ) . into_iter ( ) . chain ( arguments ) . map ( | x | x . to_raw ( & mut self . gc ) ) . collect ( ) ; // Having to construct a chunk here isn't the most clean, but it's the simplest way of making // the VM perform a function call. It reuses sanity checks such as ensuring `function` // can actually be called. let mut chunk = Chunk :: new ( Rc :: from ( " " ) ) ; chunk . emit ( ( Opcode :: Call , // 1 has to be subtracted from the stack length there because the VM itself adds 1 to // count in the function argument. Opr24 :: try_from ( stack . len ( ) - 1 ) . map_err ( | _ | Error :: TooManyArguments ) ? , ) ) ; chunk . emit ( Opcode :: Halt ) ; let chunk = Rc :: new ( chunk ) ; let fiber = Fiber { engine : self , inner : vm :: Fiber :: new ( chunk , stack ) , } ; fiber . trampoline ( ) }
Calls the provided function with the given arguments.
Calls the provided function with the given arguments .
&mut self
function
Value
arguments
impl IntoIterator<Item = Value>
errors
[`Error::Runtime`] - if a runtime error occurs - `function` isn't callable or an error is
raised during execution
[`Error::TooManyArguments`] - if more arguments than the implementation can support is
passed to the function
[ ` Error :: Runtime ` ] - if a runtime error occurs - ` function ` isn ' t callable or an error is raised during execution [ ` Error :: TooManyArguments ` ] - if more arguments than the implementation can support is passed to the function