Skip to content

Commit 5c96cd8

Browse files
authored
Add CallableX and MethodCallableX classes (#829)
1 parent 0bdb75c commit 5c96cd8

File tree

13 files changed

+4198
-1042
lines changed

13 files changed

+4198
-1042
lines changed

harness/tests/src/main/kotlin/godot/tests/callable/CallableMethodBindTest.kt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import godot.api.Node
44
import godot.annotation.RegisterClass
55
import godot.annotation.RegisterFunction
66
import godot.annotation.RegisterProperty
7-
import godot.core.MethodCallable
7+
import godot.core.Callable0
8+
import godot.core.Callable1
9+
import godot.core.Callable2
10+
import godot.core.Callable3
811
import godot.core.VariantArray
9-
import godot.core.toGodotName
12+
import godot.core.callable3
1013
import godot.core.variantArrayOf
1114
import godot.global.GD
1215

@@ -17,22 +20,28 @@ class CallableMethodBindTest: Node() {
1720

1821
@RegisterFunction
1922
fun callWithMethodWithAllBinds() {
20-
MethodCallable(this, CallableMethodBindTest::readySignalMethodBindTest.toGodotName()).bindUnsafe(1, 2, 3).callUnsafe()
23+
val unboundCallable: Callable3<Unit, Int, Int, Int> = callable3(CallableMethodBindTest::readySignalMethodBindTest)
24+
val boundCallable: Callable0<Unit> = unboundCallable.bind(1, 2, 3)
25+
boundCallable.call()
2126
}
2227

2328
@RegisterFunction
2429
fun callWithMethodWithTwoBinds() {
25-
MethodCallable(this, CallableMethodBindTest::readySignalMethodBindTest.toGodotName()).bindUnsafe(2, 3).callUnsafe(0)
30+
val unboundCallable: Callable3<Unit, Int, Int, Int> = callable3(CallableMethodBindTest::readySignalMethodBindTest)
31+
val boundCallable: Callable1<Unit, Int> = unboundCallable.bind(5, 6)
32+
boundCallable.call(4)
2633
}
2734

2835
@RegisterFunction
2936
fun callWithMethodWithOneBind() {
30-
MethodCallable(this, CallableMethodBindTest::readySignalMethodBindTest.toGodotName()).bindUnsafe(3).callUnsafe(0, 0)
37+
val unboundCallable: Callable3<Unit, Int, Int, Int> = callable3(CallableMethodBindTest::readySignalMethodBindTest)
38+
val boundCallable: Callable2<Unit, Int, Int> = unboundCallable.bind(9)
39+
boundCallable.call(7, 8)
3140
}
3241

3342
@RegisterFunction
3443
fun callWithMethodWithNoBind() {
35-
MethodCallable(this, CallableMethodBindTest::readySignalMethodBindTest.toGodotName()).bindUnsafe().callUnsafe(0, 0, 0)
44+
callable3(CallableMethodBindTest::readySignalMethodBindTest).call(10, 11, 12)
3645
}
3746

3847
@RegisterFunction

harness/tests/test/unit/test_callable_method_bind.gd

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ func test_method_bind_passing_correct_binds_with_one_args_provided() -> void:
2626
binds_test_script.call_with_method_with_two_binds()
2727
assert_eq(
2828
binds_test_script.method_binds[0],
29-
0,
29+
4,
3030
"Incorrect bind value passed"
3131
)
3232
assert_eq(
3333
binds_test_script.method_binds[1],
34-
2,
34+
5,
3535
"Incorrect bind value passed"
3636
)
3737
assert_eq(
3838
binds_test_script.method_binds[2],
39-
3,
39+
6,
4040
"Incorrect bind value passed"
4141
)
4242
binds_test_script.free()
@@ -46,17 +46,17 @@ func test_method_bind_passing_correct_binds_with_two_args_provided() -> void:
4646
binds_test_script.call_with_method_with_one_bind()
4747
assert_eq(
4848
binds_test_script.method_binds[0],
49-
0,
49+
7,
5050
"Incorrect bind value passed"
5151
)
5252
assert_eq(
5353
binds_test_script.method_binds[1],
54-
0,
54+
8,
5555
"Incorrect bind value passed"
5656
)
5757
assert_eq(
5858
binds_test_script.method_binds[2],
59-
3,
59+
9,
6060
"Incorrect bind value passed"
6161
)
6262
binds_test_script.free()
@@ -66,17 +66,17 @@ func test_method_bind_passing_correct_binds_with_three_args_provided() -> void:
6666
binds_test_script.call_with_method_with_no_bind()
6767
assert_eq(
6868
binds_test_script.method_binds[0],
69-
0,
69+
10,
7070
"Incorrect bind value passed"
7171
)
7272
assert_eq(
7373
binds_test_script.method_binds[1],
74-
0,
74+
11,
7575
"Incorrect bind value passed"
7676
)
7777
assert_eq(
7878
binds_test_script.method_binds[2],
79-
0,
79+
12,
8080
"Incorrect bind value passed"
8181
)
8282
binds_test_script.free()

0 commit comments

Comments
 (0)