Can a Kotlin script reference itself


#1

Hi all!

I’ve noticed that you can not use the “this” keyword in a script.  I have the need to pass a script reference to a method.  Can this be done?

-Steve


#2

By the way, I've used an object as a work around as follows, but this isn't pretty.  It would be nicer if I could declare all these functions at the top level:

val testUtils = TestUtils(vertx)

verticle.onStop = {
  testUtils.unregisterAll()
  testUtils.appStopped()
}

verticle.onStart = {
  println(“Starting up baby!”)
  testUtils.registerTests(object  {
  fun testPutAtGetAtByte() {
           val buffer = Buffer()
           val b: Byte = 12
           buffer.setByte(10, b)
           testUtils.azzert(buffer.getByte(10) == b)
           testUtils.testComplete()
  }

    fun testPutAtInt() {

           val buffer = Buffer()
           val i = 1233
           buffer.setInt(10, i)
           testUtils.azzert(buffer.getInt(10) == i)
           testUtils.testComplete()
  }

    fun testPutAtLong() {

           val buffer = Buffer()
           val l: Long = 1233
           buffer.setLong(10, l)
           testUtils.azzert(buffer.getLong(10) == l)
           testUtils.testComplete()
  }

    fun testPutAtShort() {

           val buffer = Buffer()
           val s: Short = 123
           buffer.setShort(10, s)
           testUtils.azzert(buffer.getShort(10) == s)
           testUtils.testComplete()
  }

    fun testPutAtDouble() {

           val buffer = Buffer()
           val d: Double = 123.123
           buffer.setDouble(10, d)
           testUtils.azzert(buffer.getDouble(10) == d)
           testUtils.testComplete()
  }

    fun testPutAtFloat() {

           val buffer = Buffer()
           val f: Float = 123.123.toFloat()
           buffer.setFloat(10, f)
           testUtils.azzert(buffer.getFloat(10) == f)
           testUtils.testComplete()
  }

    fun testPutAtBuffer() {

           val buffer = Buffer()
           val b = TestUtils.generateRandomBuffer(10)
           buffer.setBuffer(10, b)
           testUtils.azzert(TestUtils.buffersEqual(buffer.getBuffer(10, 20), b))
           testUtils.testComplete()
  }
  })
  testUtils.appReady()
}


#3

To my knowledge this is not supported yet