You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Move from KSP to classgraph for registration code and initial Scala support (#761)
* feat: Add java and kotlin parser to get fqdn from source code
* feat: remove script source file path from KtClass and registration.
* feat: First draft of ClassGraph symbol processor
* enh(entry-gen): Disallow multiple constructors with same argument count and simplify constructor registration so we get rid of nullable info need
* feat(entry-gen): Manage type parameters with classgraph
* feat(classgraph): get signal parameter names from annotation
* feat(classgraph): generate registrars using classgraph
* feat: configure gradle plugin to use classgraph instead of KSP and first steps in scala support
* feat: Add update of gdj files
* feat: Add support of scala source script in engine
* feat: set scala version configurable from gradle plugin
* chore: remove classes to test parser
* feat: Remove support for registering constructors with arguments
* feat: Remove multi args constructor constraints and simplify code according to this modification
* chore: update scala implementation code to godot 4.4 and add scala call test
* chore: rename fqdn to fqName
* enh: fail on errors at the end of classgraph process
* doc: Add scala support to documentation
* enh: Add context on classgraph errors
* chore: regenerate api with godot kotlin json
---------
Co-authored-by: Ced Naru <cednaru.dev@gmail.com>
Co-authored-by: chippmann <cedric@hippmann.ch>
Copy file name to clipboardExpand all lines: docs/src/doc/contribution/knowledge-base/entry-generation.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@
5
5
To make it more language agnostic, the entry generator provides a set of model classes which represent the needed information about the source code by the entry genenerator.
6
6
It expects this information to be gathered and assembled by the calling tool and to be provided in the entry point of the entry generator.
7
7
8
-
For Kotlinand Java, this tool is `godot-kotlin-symbol-processor` (a Kotlin compiler's plugin), which analyses the source code, and gathers the information needed by the entry generator.
8
+
For Kotlin, Java and Scala, this tool is `godot-class-graph-symbol-processor`, which analyses the byte code, and gathers the information needed by the entry generator.
9
9
It then calls the entry generator which in turn generates the needed entry files.
Copy file name to clipboardExpand all lines: docs/src/doc/index.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -36,7 +36,7 @@ The items in this list are explicitly mentioned here as these will be implemente
36
36
Also consider the [API Differences](user-guide/api-differences.md) section for general differences
37
37
and limitations which will not be or cannot be adressed in the near forseable future or ever.
38
38
39
-
-Each registered constructor must have a unique number of arguments, constructor overloading is not yet supported.
39
+
-Only a default no arg constructor can be registered.
40
40
- No tool mode (you can set it already in the `@RegisterClass` annotation but it has no effect yet).
41
41
- No addon support, you cannot use Godot Kotlin/JVM to write plugins and addons yet (you can however [write libraries](develop-libraries/introduction.md) with godot specific code).
42
42
- Web is currently not supported. See [Supported platforms](#supported-platforms) to see what platforms we currently support
@@ -48,7 +48,7 @@ If you don't have Discord or you don't want to use it, please file an issue on G
48
48
49
49
## Supported languages
50
50
51
-
The main language supported is Kotlin. We do however support Java experimentally. It should be possible to support other JVM-based languages as well but this is not the focus of this project. If you want to have support for other languages, have a look at [support for other JVM-based languages](contribution/support-for-other-jvm-based-languages.md).
51
+
The main language supported is Kotlin. We do however support Java and Scala experimentally. It should be possible to support other JVM-based languages as well but this is not the focus of this project. If you want to have support for other languages, have a look at [support for other JVM-based languages](contribution/support-for-other-jvm-based-languages.md).
52
52
53
53
## Supported platforms
54
54
@@ -85,7 +85,7 @@ Contrary to the official binaries, there are two builds of the editor per Platfo
85
85
`release` editors are the editors you use normally. `debug` editors provide debug symbols and are intended to provide better stacktraces in case of crashes of the editor. Please use those when submitting bugreports.
86
86
87
87
!!! warning
88
-
This module will NOT work with the official Godot Editor and Export Templates! To be able to use Kotlinand Java scripts in Godot, you need our Editor and Export Templates builds.
88
+
This module will NOT work with the official Godot Editor and Export Templates! To be able to use Kotlin, Java and Scala scripts in Godot, you need our Editor and Export Templates builds.
Copy file name to clipboardExpand all lines: docs/src/doc/user-guide/api-differences.md
+19-4
Original file line number
Diff line number
Diff line change
@@ -5,9 +5,9 @@ Godot Kotlin/JVM offers two different ways to attach scripts:
5
5
- Source files
6
6
- Registration files.
7
7
8
-
## Source files .ktand .java
8
+
## Source files .kt, .java and .scala
9
9
10
-
Just like you would do with GDScript, you can directly attach your Kotlin/Java files to Nodes as scripts.
10
+
Just like you would do with GDScript, you can directly attach your Kotlin/Java/Scala files to Nodes as scripts.
11
11
This is the most straightforward method to use Kotlin scripts but not the most flexible.
12
12
13
13
The limitations are the following:
@@ -20,7 +20,7 @@ The limitations are the following:
20
20
var test_script:MyScript= load("res://pathToScript/MyScript.kt").new() // Wrong
21
21
var test_script:Node= load("res://pathToScript/MyScript.kt").new() // Correct
22
22
```
23
-
The same applies if you use a Godotobject with a .kt/.java attached to it
23
+
The same applies if you use a Godotobject with a .kt/.java/.scala attached to it
24
24
25
25
If those limitations don't apply to you, feel free to use Kotlin source files directly.
26
26
@@ -32,7 +32,7 @@ They have several benefits over source files:
32
32
- .gdj can be placed wherever you want in your Godot project, you are not limited to the source set.
33
33
- Each script get its own .gdj. This includes scripts in different modules and libraries.
34
34
- If a source file contains several scripts. A different .gdj will be generated for each.
35
-
- Registration files are language agnostic, they are generated for Kotlinand Java files with no difference.
35
+
- Registration files are language agnostic, they are generated for Kotlin, Java and Scala files with no difference.
36
36
- When creating a script from code using its registered name. The module is going to use the registration file as the script. Therefore, registration files are treated as the default way to use scripts inside the module.
37
37
38
38
By default, these files are generated into a folder called `gdj` in the root of your project.
@@ -186,6 +186,14 @@ This kind of operation can be costly so we provide extension functions which cac
186
186
```
187
187
///
188
188
189
+
/// tab | Scala
190
+
```scala
191
+
val stringName = StringNames.asCachedStringName("myString")
192
+
val nodePath = NodePaths.asCachedNodePath("myNode/myChildNode")
193
+
val snakeCaseStringName = StringNames.toGodotName("myString")
194
+
```
195
+
///
196
+
189
197
You can also use the non-cached version of them if you simply want ease of conversion:
190
198
191
199
/// tab | Kotlin
@@ -202,6 +210,13 @@ You can also use the non-cached version of them if you simply want ease of conve
202
210
```
203
211
///
204
212
213
+
/// tab | Scala
214
+
```scala
215
+
val stringName = StringNames.asStringName("myString")
216
+
val nodePath = NodePaths.asNodePath("myNode/myChildNode")
Copy file name to clipboardExpand all lines: docs/src/doc/user-guide/classes.md
+5-15
Original file line number
Diff line number
Diff line change
@@ -139,12 +139,9 @@ This also works for any type you define.
139
139
140
140
## Constructors
141
141
142
-
Godot requires you to have a default constructor on your classes.
143
-
You can define additional constructors but you have to register them by annothing them with `@RegisterConstructor`.
144
-
Default constructors, on the other hand, are always registered automatically.
145
-
146
-
Constructors can also have **a maximum of 8 arguments** and must have a unique argument count as constructor overloading is not yet supported.
147
-
This limitation is only for registered constructors.
142
+
Godot requires you to have a default constructor on your classes. These are automatically registered for you.
143
+
Registering constructor with arguments is currently not supported. But you can freely use them from Kotlin/Java/Scala
144
+
just not from GDScript or any other non Godot Kotlin/JVM language.
148
145
149
146
### Instantiate Kotlin script classes in GDScript
150
147
@@ -154,15 +151,8 @@ From GDScript it is possible to create an instance of a Kotlin class using the d
154
151
var instance :=YourKotlinClass.new()
155
152
```
156
153
157
-
Additional constructors must use the `load` function:
158
-
159
-
```kt
160
-
var instance := load("res://gdj/YourClass.gdj").new(oneArg, anotherArg)
161
-
```
162
-
163
-
!!! info
164
-
The limitation of max 16 arguments for constructors is arbitrary. We decided to introduce this limitation to prevent performance bottlenecks for creating objects as each argument passed to a constructor needs to be unpacked by the binding. The more arguments, the more unpacking is needed which means more overhead.
165
-
154
+
Using other constructors is not possible. Only the default no arg constructor is registered.
155
+
But you can create the object and set the required properties after instantiation.
Copy file name to clipboardExpand all lines: harness/tests/scripts/dependencies/fqname-library-tests/godot/tests/library/fqname/godot_tests_library_fqname_FQNLSimple.gdj
Copy file name to clipboardExpand all lines: harness/tests/scripts/dependencies/fqname-library-tests/godot/tests/library/fqname/godot_tests_library_fqname_FQNLSimpleChild.gdj
Copy file name to clipboardExpand all lines: harness/tests/scripts/dependencies/hierarchical-library-tests/godot/tests/library/hierarchical/HLSimple.gdj
0 commit comments