fixed invoke overriden field problem in dynamic and the dynamic's Lyng class.

This commit is contained in:
Sergey Chernov 2025-11-01 22:07:22 +01:00
parent ba725fc9ed
commit b8d6ff01a6
2 changed files with 21 additions and 3 deletions

View File

@ -47,7 +47,9 @@ class ObjDynamicContext(val delegate: ObjDynamic) : Obj() {
}
}
open class ObjDynamic(var readCallback: Statement? = null,var writeCallback: Statement? = null) : Obj() {
open class ObjDynamic(var readCallback: Statement? = null, var writeCallback: Statement? = null) : Obj() {
override val objClass: ObjClass = type
override suspend fun readField(scope: Scope, name: String): ObjRecord {
return readCallback?.execute(scope.createChildScope(Arguments(ObjString(name))))?.let {
@ -59,13 +61,29 @@ open class ObjDynamic(var readCallback: Statement? = null,var writeCallback: Sta
?: super.readField(scope, name)
}
override suspend fun invokeInstanceMethod(
scope: Scope,
name: String,
args: Arguments,
onNotFoundResult: (() -> Obj?)?
): Obj {
val over = readCallback?.execute(
scope.createChildScope(
Arguments(ObjString(name)
)
)
)
return over?.invoke(scope, scope.thisObj, args)
?: super.invokeInstanceMethod(scope, name, args, onNotFoundResult)
}
override suspend fun writeField(scope: Scope, name: String, newValue: Obj) {
writeCallback?.execute(scope.createChildScope(Arguments(ObjString(name), newValue)))
?: super.writeField(scope, name, newValue)
}
override suspend fun getAt(scope: Scope, index: Obj): Obj {
return readCallback?.execute( scope.createChildScope(Arguments(index)))
return readCallback?.execute(scope.createChildScope(Arguments(index)))
?: super.getAt(scope, index)
}

View File

@ -183,7 +183,7 @@ class OOTest {
x(1,2,3)
assertEquals(6, x(1,2,3))
// v HERE v
assertEquals(15, (cc.foo.bar)(10,2,3))
assertEquals(15, cc.foo.bar(10,2,3))
""")
}
}