utopia-rise / godot-kotlin-jvm

Godot Kotlin JVM Module
MIT License
636 stars 44 forks source link

Streamlining: Remove JClass and ClassLoader from JavaInstanceWrapper #484

Closed CedNaru closed 1 year ago

CedNaru commented 1 year ago

JClass and ClassLoader were passed around a lot in that module because they were constructor arguments and properties of the JavaInstanceWrapper, parent of many other classes necessary to communicate with the JVM. This was unnecessary as they were only useful once to initialize the JNI methods, which so far was done in the constructor directly.

I got rid of that and replaced most of the contructor content by a static function that will setup everything JNI needs.

As a bonus, there was actually a single use of JClass after initialization inside the inherit_scriptmethod from KotlinScript but it wasn't working anyway as we were comparing the JClass of KtClass itself and not the JVM class it was wrapping. I replaced that by adding to KtClass the list of script ancestor (not just the direct one). I also implemented the missing function get_base_script related to that matter.