Skip to content

Add CallableX and MethodCallableX classes #829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import godot.api.Node
import godot.annotation.RegisterClass
import godot.annotation.RegisterFunction
import godot.annotation.RegisterProperty
import godot.core.MethodCallable
import godot.core.Callable0
import godot.core.Callable1
import godot.core.Callable2
import godot.core.Callable3
import godot.core.VariantArray
import godot.core.toGodotName
import godot.core.callable3
import godot.core.variantArrayOf
import godot.global.GD

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

@RegisterFunction
fun callWithMethodWithAllBinds() {
MethodCallable(this, CallableMethodBindTest::readySignalMethodBindTest.toGodotName()).bindUnsafe(1, 2, 3).callUnsafe()
val unboundCallable: Callable3<Unit, Int, Int, Int> = callable3(CallableMethodBindTest::readySignalMethodBindTest)
val boundCallable: Callable0<Unit> = unboundCallable.bind(1, 2, 3)
boundCallable.call()
}

@RegisterFunction
fun callWithMethodWithTwoBinds() {
MethodCallable(this, CallableMethodBindTest::readySignalMethodBindTest.toGodotName()).bindUnsafe(2, 3).callUnsafe(0)
val unboundCallable: Callable3<Unit, Int, Int, Int> = callable3(CallableMethodBindTest::readySignalMethodBindTest)
val boundCallable: Callable1<Unit, Int> = unboundCallable.bind(5, 6)
boundCallable.call(4)
}

@RegisterFunction
fun callWithMethodWithOneBind() {
MethodCallable(this, CallableMethodBindTest::readySignalMethodBindTest.toGodotName()).bindUnsafe(3).callUnsafe(0, 0)
val unboundCallable: Callable3<Unit, Int, Int, Int> = callable3(CallableMethodBindTest::readySignalMethodBindTest)
val boundCallable: Callable2<Unit, Int, Int> = unboundCallable.bind(9)
boundCallable.call(7, 8)
}

@RegisterFunction
fun callWithMethodWithNoBind() {
MethodCallable(this, CallableMethodBindTest::readySignalMethodBindTest.toGodotName()).bindUnsafe().callUnsafe(0, 0, 0)
callable3(CallableMethodBindTest::readySignalMethodBindTest).call(10, 11, 12)
}

@RegisterFunction
Expand Down
18 changes: 9 additions & 9 deletions harness/tests/test/unit/test_callable_method_bind.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ func test_method_bind_passing_correct_binds_with_one_args_provided() -> void:
binds_test_script.call_with_method_with_two_binds()
assert_eq(
binds_test_script.method_binds[0],
0,
4,
"Incorrect bind value passed"
)
assert_eq(
binds_test_script.method_binds[1],
2,
5,
"Incorrect bind value passed"
)
assert_eq(
binds_test_script.method_binds[2],
3,
6,
"Incorrect bind value passed"
)
binds_test_script.free()
Expand All @@ -46,17 +46,17 @@ func test_method_bind_passing_correct_binds_with_two_args_provided() -> void:
binds_test_script.call_with_method_with_one_bind()
assert_eq(
binds_test_script.method_binds[0],
0,
7,
"Incorrect bind value passed"
)
assert_eq(
binds_test_script.method_binds[1],
0,
8,
"Incorrect bind value passed"
)
assert_eq(
binds_test_script.method_binds[2],
3,
9,
"Incorrect bind value passed"
)
binds_test_script.free()
Expand All @@ -66,17 +66,17 @@ func test_method_bind_passing_correct_binds_with_three_args_provided() -> void:
binds_test_script.call_with_method_with_no_bind()
assert_eq(
binds_test_script.method_binds[0],
0,
10,
"Incorrect bind value passed"
)
assert_eq(
binds_test_script.method_binds[1],
0,
11,
"Incorrect bind value passed"
)
assert_eq(
binds_test_script.method_binds[2],
0,
12,
"Incorrect bind value passed"
)
binds_test_script.free()
Loading
Loading