first documentation run
This commit is contained in:
parent
e065108f58
commit
f59e6a5fd5
21 changed files with 64 additions and 23 deletions
|
@ -10,7 +10,7 @@ use crate::{
|
|||
use core::fmt::Debug;
|
||||
use std::{cell::RefCell, fmt::Display, rc::Rc};
|
||||
|
||||
/// A lox function.
|
||||
/// A Lox function with name, parameters, body, and closure environment.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Function {
|
||||
pub name: Token,
|
||||
|
@ -62,6 +62,8 @@ impl Callable for Function {
|
|||
}
|
||||
|
||||
impl Function {
|
||||
/// Bind a method to an instance, creating a new function with "this" defined in its environment.
|
||||
/// This allows methods to access the instance they belong to.
|
||||
pub fn bind(&self, instance: Rc<RefCell<Instance>>) -> Self {
|
||||
let mut env = Environment::with_enclosing(self.closure.clone());
|
||||
env.define("this".to_string(), Value::Instance(instance));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue