-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement KotlinCallableCustom to enable lambda callables (#657)
- Loading branch information
Showing
42 changed files
with
5,257 additions
and
1,476 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// THIS FILE IS GENERATED! DO NOT EDIT OR DELETE IT. EDIT OR DELETE THE ASSOCIATED SOURCE CODE FILE INSTEAD | ||
// Note: You can however freely move this file inside your godot project if you want. Keep in mind however, that if you rename the originating source code file, this file will be deleted and regenerated as a new file instead of being updated! Other modifications to the source file however, will result in this file being updated. | ||
|
||
registeredName = LambdaCallableTest | ||
fqName = godot.tests.LambdaCallableTest | ||
relativeSourcePath = src/main/kotlin/godot/tests/LambdaCallableTest.kt | ||
baseType = Node | ||
supertypes = [ | ||
godot.Node, | ||
godot.Object, | ||
godot.core.KtObject, | ||
kotlin.Any | ||
] | ||
signals = [ | ||
signal_no_param, | ||
signal_with_params | ||
] | ||
properties = [ | ||
has_signal_no_param_been_triggered, | ||
signal_string, | ||
signal_long, | ||
signal_node, | ||
kt_callable, | ||
kt_callable_string | ||
] | ||
functions = [ | ||
_ready, | ||
emit_signal_no_param, | ||
emit_signal_with_param | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
harness/tests/src/main/kotlin/godot/tests/LambdaCallableTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package godot.tests | ||
|
||
import godot.Node | ||
import godot.annotation.RegisterClass | ||
import godot.annotation.RegisterFunction | ||
import godot.annotation.RegisterProperty | ||
import godot.annotation.RegisterSignal | ||
import godot.core.callable.asCallable | ||
import godot.signals.connect | ||
import godot.signals.signal | ||
|
||
@RegisterClass | ||
class LambdaCallableTest : Node() { | ||
|
||
@RegisterSignal | ||
val signalNoParam by signal() | ||
|
||
@RegisterProperty | ||
var hasSignalNoParamBeenTriggered = false | ||
|
||
@RegisterSignal | ||
val signalWithParams by signal<String, Long, Node>("str", "long", "node") | ||
|
||
@RegisterProperty | ||
lateinit var signalString: String | ||
|
||
@RegisterProperty | ||
var signalLong: Long = Long.MIN_VALUE | ||
|
||
@RegisterProperty | ||
lateinit var signalNode: Node | ||
|
||
@RegisterProperty | ||
var ktCallable = { str: String -> ktCallableString = str }.asCallable() | ||
|
||
@RegisterProperty | ||
lateinit var ktCallableString: String | ||
|
||
@RegisterFunction | ||
override fun _ready() { | ||
signalNoParam.connect { | ||
hasSignalNoParamBeenTriggered = true | ||
} | ||
|
||
signalWithParams.connect { p0, p1, p2 -> | ||
signalString = p0 | ||
signalLong = p1 | ||
signalNode = p2 | ||
} | ||
} | ||
|
||
@RegisterFunction | ||
fun emitSignalNoParam() { | ||
signalNoParam.emit() | ||
} | ||
|
||
@RegisterFunction | ||
fun emitSignalWithParam(str: String, long: Long, node: Node) { | ||
signalWithParams.emit(str, long, node) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
extends "res://addons/gut/test.gd" | ||
|
||
|
||
func test_signal_without_param(): | ||
var lambda_callable_test_script = LambdaCallableTest.new() | ||
get_tree().root.add_child(lambda_callable_test_script) | ||
lambda_callable_test_script.emit_signal_no_param() | ||
assert_true(lambda_callable_test_script.has_signal_no_param_been_triggered) | ||
get_tree().root.remove_child(lambda_callable_test_script) | ||
lambda_callable_test_script.free() | ||
|
||
func test_signal_with_param(): | ||
var lambda_callable_test_script = LambdaCallableTest.new() | ||
get_tree().root.add_child(lambda_callable_test_script) | ||
|
||
var expected_str = "expected" | ||
var expected_int = randi() | ||
var expected_node = lambda_callable_test_script | ||
|
||
lambda_callable_test_script.emit_signal_with_param(expected_str, expected_int, expected_node) | ||
|
||
assert_eq(lambda_callable_test_script.signal_string, expected_str) | ||
assert_eq(lambda_callable_test_script.signal_long, expected_int) | ||
assert_eq(lambda_callable_test_script.signal_node, expected_node) | ||
get_tree().root.remove_child(lambda_callable_test_script) | ||
lambda_callable_test_script.free() | ||
|
||
func test_kotlin_lambda_call_from_gdscript(): | ||
var lambda_callable_test_script = LambdaCallableTest.new() | ||
|
||
var expected_str = "expected" | ||
|
||
lambda_callable_test_script.kt_callable.call(expected_str) | ||
|
||
assert_eq(lambda_callable_test_script.kt_callable_string, expected_str) | ||
lambda_callable_test_script.free() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
kt/api-generator/src/main/kotlin/godot/codegen/services/IKtCallableGenerationService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package godot.codegen.services | ||
|
||
import com.squareup.kotlinpoet.FileSpec | ||
|
||
interface IKtCallableGenerationService { | ||
fun generate(maxArgumentCount: Int): FileSpec | ||
} |
7 changes: 7 additions & 0 deletions
7
kt/api-generator/src/main/kotlin/godot/codegen/services/ISignalGenerationService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package godot.codegen.services | ||
|
||
import com.squareup.kotlinpoet.FileSpec | ||
|
||
interface ISignalGenerationService { | ||
fun generate(maxArgumentCount: Int): FileSpec | ||
} |
Oops, something went wrong.