fixed invoke overriden field problem in dynamic and the dynamic's Lyng class.
This commit is contained in:
		
							parent
							
								
									ba725fc9ed
								
							
						
					
					
						commit
						b8d6ff01a6
					
				@ -49,6 +49,8 @@ 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 {
 | 
					    override suspend fun readField(scope: Scope, name: String): ObjRecord {
 | 
				
			||||||
        return readCallback?.execute(scope.createChildScope(Arguments(ObjString(name))))?.let {
 | 
					        return readCallback?.execute(scope.createChildScope(Arguments(ObjString(name))))?.let {
 | 
				
			||||||
            if (writeCallback != null)
 | 
					            if (writeCallback != null)
 | 
				
			||||||
@ -59,6 +61,22 @@ open class ObjDynamic(var readCallback: Statement? = null,var writeCallback: Sta
 | 
				
			|||||||
            ?: super.readField(scope, name)
 | 
					            ?: 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) {
 | 
					    override suspend fun writeField(scope: Scope, name: String, newValue: Obj) {
 | 
				
			||||||
        writeCallback?.execute(scope.createChildScope(Arguments(ObjString(name), newValue)))
 | 
					        writeCallback?.execute(scope.createChildScope(Arguments(ObjString(name), newValue)))
 | 
				
			||||||
            ?: super.writeField(scope, name, newValue)
 | 
					            ?: super.writeField(scope, name, newValue)
 | 
				
			||||||
 | 
				
			|||||||
@ -183,7 +183,7 @@ class OOTest {
 | 
				
			|||||||
            x(1,2,3)
 | 
					            x(1,2,3)
 | 
				
			||||||
            assertEquals(6, x(1,2,3))
 | 
					            assertEquals(6, x(1,2,3))
 | 
				
			||||||
            //               v  HERE    v
 | 
					            //               v  HERE    v
 | 
				
			||||||
            assertEquals(15, (cc.foo.bar)(10,2,3))
 | 
					            assertEquals(15, cc.foo.bar(10,2,3))
 | 
				
			||||||
       """)
 | 
					       """)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user