You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
602 B
Kotlin

package fr.celticinfo.lox
class LoxInstance(private val klass: LoxClass) {
private val fields = mutableMapOf<String, Any?>()
fun get(name: Token): Any? {
if (fields.containsKey(name.lexeme)) {
return fields[name.lexeme]
}
val method = klass.findMethod(name.lexeme)
if (method != null) {
return method.bind(this)
}
throw RuntimeError(name, "Undefined property '${name.lexeme}'.")
}
fun set(name: Token, value: Any?) {
fields[name.lexeme] = value
}
override fun toString() = "$klass instance"
}