package ru.dbotthepony.kstarbound.lua @Retention(AnnotationRetention.RUNTIME) @Target(AnnotationTarget.PROPERTY, AnnotationTarget.FUNCTION) annotation class LuaExposed interface ILuaIndex { fun luaIndex(index: Any?): Any? } interface ILuaNewIndex { fun luaIndex(index: Any?, value: Any?) } class JVM2LuaWrapper(val value: R) { private abstract class LuaBinding { abstract fun invoke(receiver: R, values: Array): Any? abstract fun read(receiver: R): Any? abstract fun write(receiver: R, value: Any?) } private class LuaFunctionBinding(private val func: (R, Array) -> Any?) : LuaBinding() { override fun invoke(receiver: R, values: Array): Any? { return func.invoke(receiver, values) } override fun read(receiver: R) { throw UnsupportedOperationException("attempt to index a function value") } override fun write(receiver: R, value: Any?) { throw UnsupportedOperationException("attempt to new index a function value") } } private class LuaPropertyBinding(private val read: (R) -> Any?, private val write: ((R, Any?) -> Unit)?) : LuaBinding() { override fun invoke(receiver: R, values: Array): Any? { throw UnsupportedOperationException("attempt to call a value") } override fun read(receiver: R): Any? { return read.invoke(receiver) } override fun write(receiver: R, value: Any?) { if (write == null) throw UnsupportedOperationException("attempt to new index a read-only value") write.invoke(receiver, value) } } companion object { //private val decls = } }