utopia-rise/godot-kotlin-native

Use of inline classes in Generated classes

piiertho opened this issue · 1 comments

Describe the problem or limitation you are having in your project:

We'd like to try inline classes to wrap c pointer into generated class, without overhead.
This needs use of interface for inheritance, internal Objects to store methods and method bindings, and inline classes to store the pointer.

Describe how this feature / enhancement will help you overcome this problem or limitation:

Not appropriate.

Show a mock up screenshots/video or a flow diagram explaining how your proposal will work:

None to provide.

Describe implementation detail for your proposal (in code), if possible:

interface Node {
    fun getParent(): Node?
}
interface Spatial : Node

internal object SpatialMethods {
}

internal object NodeMethods {
    fun getParent(ptr: COpaquePointer): Node? {
        TODO("Not yet implemented")
    }
}

inline class SpatialImpl(private val ptr: COpaquePointer) : Spatial {
    override fun getParent(): Node? {
        return NodeMethods.getParent(ptr)
    }
}

inline class NodeImpl(private val ptr: COpaquePointer) : Node {
    override fun getParent(): Node? = NodeMethods.getParent(ptr)
}
// pseudo constructors
fun Node(): Node = TODO()
fun Spatial(): Spatial = TODO()

fun test() {
    val spatial = Spatial()
    val node = Node()
}

If this enhancement will not be used often, can it be worked around with a few lines of code?:

Not appropriate;

Is there a reason why this should be in this project and not individually solved?:

It concerns API code generation.

With this way to do, user cannot easily extends a godot class.
I also encounter problems on macos when compiling because it generates much more source code. I had to increase gradle's memory to 3g. And even with this option the compiler was still running 2 hours later...
I close this issue for now. I'll implement old code generation back and then we'll see where to optimize using performance analytics.