Add methods on classes
parent
22a4d86160
commit
fd71a46ede
@ -1,11 +1,15 @@
|
||||
package fr.celticinfo.lox
|
||||
|
||||
class LoxClass(private val name: String) : LoxCallable {
|
||||
class LoxClass(private val name: String, private val methods: Map<String, LoxFunction>) : LoxCallable {
|
||||
override fun call(interpreter: Interpreter, arguments: List<Any?>): Any? {
|
||||
val instance = LoxInstance(this)
|
||||
return instance
|
||||
}
|
||||
|
||||
fun findMethod(name: String): LoxFunction? {
|
||||
return methods[name]
|
||||
}
|
||||
|
||||
override fun arity() = 0
|
||||
|
||||
override fun toString() = name
|
||||
|
||||
Loading…
Reference in New Issue