public LoxFunction Bind(LoxInstance instance) { var environment = new Environment(closure); environment.Define("this", instance); return(new LoxFunction(declaration, environment, isInitializer)); }
public object Call(Interpreter interpreter, List <object> arguments) { var instance = new LoxInstance(this); var initializer = FindMethod(instance, "init"); if (initializer != null) { initializer.Call(interpreter, arguments); } return(instance); }
public LoxFunction FindMethod(LoxInstance instance, string name) { if (methods.ContainsKey(name)) { return(methods[name].Bind(instance)); } if (superClass != null) { return(superClass.FindMethod(instance, name)); } return(null); }