lox_one/
callable.rs

1use crate::interpreter::Interpreter;
2use crate::lox_value::LoxValue;
3
4use crate::interpreter::error::RuntimeResult;
5
6/// This trait is shared among all types that can be called
7/// like functions and class instantiations.
8pub trait Callable {
9    /// Returns the name of the callable.
10    fn name(&self) -> String;
11    /// Returns the number of arguments taken by the callable.
12    fn arity(&self) -> usize;
13    /// Takes a `&mut Interpreter` and calls the function on it.
14    fn call(&self, interpreter: &mut Interpreter, args: &[LoxValue]) -> RuntimeResult<LoxValue>;
15}