Skip to content

Commit b10e824

Browse files
committed
Remove support for registering constructors with arguments
1 parent e5b3f8c commit b10e824

File tree

22 files changed

+11
-415
lines changed

22 files changed

+11
-415
lines changed

docs/src/doc/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The items in this list are explicitly mentioned here as these will be implemente
3636
Also consider the [API Differences](user-guide/api-differences.md) section for general differences
3737
and limitations which will not be or cannot be adressed in the near forseable future or ever.
3838

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.
4040
- No tool mode (you can set it already in the `@RegisterClass` annotation but it has no effect yet).
4141
- 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).
4242
- Web is currently not supported. See [Supported platforms](#supported-platforms) to see what platforms we currently support

docs/src/doc/user-guide/classes.md

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,9 @@ This also works for any type you define.
139139

140140
## Constructors
141141

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.
148145

149146
### Instantiate Kotlin script classes in GDScript
150147

@@ -154,15 +151,8 @@ From GDScript it is possible to create an instance of a Kotlin class using the d
154151
var instance := YourKotlinClass.new()
155152
```
156153

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.
166156

167157
## Customization
168158

harness/tests/scripts/godot/tests/MultiArgsConstructorTest.gdj

Lines changed: 0 additions & 24 deletions
This file was deleted.

harness/tests/scripts/godot/tests/args/ConstructorArgSizeTest.gdj

Lines changed: 0 additions & 22 deletions
This file was deleted.

harness/tests/src/main/kotlin/godot/tests/MultiArgsConstructorTest.kt

Lines changed: 0 additions & 68 deletions
This file was deleted.

harness/tests/src/main/kotlin/godot/tests/args/ConstructorArgSizeTest.kt

Lines changed: 0 additions & 146 deletions
This file was deleted.

harness/tests/src/main/kotlin/godot/tests/constructor/ConstructorRegistrationTest.kt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@ package godot.tests.constructor
22

33
import godot.api.Node
44
import godot.annotation.RegisterClass
5-
import godot.annotation.RegisterConstructor
6-
import godot.core.Dictionary
7-
import godot.core.VariantArray
85

96
@RegisterClass
10-
class ConstructorRegistrationTest(): Node() {
11-
12-
@RegisterConstructor
13-
constructor(param1: Dictionary<Any, Any?>, param2: VariantArray<Long>): this()
14-
}
7+
class ConstructorRegistrationTest(): Node()

kt/entry-generation/godot-class-graph-symbol-processor/src/main/kotlin/godot/annotation/processor/classgraph/extensions/AnnotationExtensions.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import godot.annotation.IntFlag
99
import godot.annotation.MultilineText
1010
import godot.annotation.PlaceHolderText
1111
import godot.annotation.RegisterClass
12-
import godot.annotation.RegisterConstructor
1312
import godot.annotation.RegisterFunction
1413
import godot.annotation.RegisterProperty
1514
import godot.annotation.RegisterSignal
@@ -34,7 +33,6 @@ import godot.entrygenerator.model.PlaceHolderTextHintAnnotation
3433
import godot.entrygenerator.model.Range
3534
import godot.entrygenerator.model.RangeHintAnnotation
3635
import godot.entrygenerator.model.RegisterClassAnnotation
37-
import godot.entrygenerator.model.RegisterConstructorAnnotation
3836
import godot.entrygenerator.model.RegisterFunctionAnnotation
3937
import godot.entrygenerator.model.RegisterPropertyAnnotation
4038
import godot.entrygenerator.model.RegisterSignalAnnotation
@@ -52,7 +50,6 @@ fun AnnotationInfo.mapToGodotAnnotation(parentDeclaration: Any): GodotAnnotation
5250
customName = parameterValues.getValue("customName") as? String,
5351
symbolProcessorSource = this
5452
)
55-
RegisterConstructor::class.java.name -> RegisterConstructorAnnotation(this)
5653
RegisterFunction::class.java.name -> RegisterFunctionAnnotation(this)
5754
RegisterProperty::class.java.name -> RegisterPropertyAnnotation(this)
5855
RegisterSignal::class.java.name -> RegisterSignalAnnotation(this)

kt/entry-generation/godot-class-graph-symbol-processor/src/main/kotlin/godot/annotation/processor/classgraph/extensions/ClassExtentions.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package godot.annotation.processor.classgraph.extensions
22

33
import godot.annotation.RegisterClass
4-
import godot.annotation.RegisterConstructor
54
import godot.annotation.RegisterFunction
65
import godot.annotation.RegisterProperty
76
import godot.annotation.RegisterSignal
@@ -58,8 +57,7 @@ fun ClassInfo.mapToClazz(settings: Settings): Clazz {
5857

5958
val constructors = constructorInfo
6059
.filter { constructor ->
61-
constructor.isPublic &&
62-
(constructor.hasAnnotation(RegisterConstructor::class.java) || constructor.parameterInfo.isEmpty())
60+
constructor.isPublic && constructor.parameterInfo.isEmpty()
6361
}
6462
.map { it.mapToRegisteredConstructor(settings) }
6563

kt/entry-generation/godot-entry-generator/src/main/kotlin/godot/entrygenerator/EntryGenerator.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package godot.entrygenerator
22

3-
import godot.entrygenerator.checks.ConstructorArgCountCheck
4-
import godot.entrygenerator.checks.ConstructorOverloadingCheck
53
import godot.entrygenerator.checks.DefaultConstructorCheck
64
import godot.entrygenerator.checks.FunctionArgCountCheck
75
import godot.entrygenerator.checks.LateinitPropertyCheck
@@ -193,8 +191,6 @@ object EntryGenerator {
193191
): Boolean {
194192
return listOf(
195193
DefaultConstructorCheck(logger, registeredClasses).execute(),
196-
ConstructorArgCountCheck(logger, registeredClasses).execute(),
197-
ConstructorOverloadingCheck(logger, registeredClasses).execute(),
198194

199195
FunctionArgCountCheck(logger, registeredClasses).execute(),
200196

0 commit comments

Comments
 (0)