summaryrefslogtreecommitdiffstats
path: root/test/src/example.cpp
diff options
context:
space:
mode:
authorDavid Snopek <dsnopek@gmail.com>2023-09-21 16:20:21 -0500
committerGitHub <noreply@github.com>2023-09-21 16:20:21 -0500
commitc44c3d5ebf9826214efc971f0cbe047789af2575 (patch)
tree5ca066cd3e84799c40defebe7923d7785bc20fe6 /test/src/example.cpp
parent4314f91b7dc23d930506f52d3a3c88fae0f5d57d (diff)
parentc18c1916c3f465d00800921d527902f18308fbf4 (diff)
downloadredot-cpp-c44c3d5ebf9826214efc971f0cbe047789af2575.tar.gz
Merge pull request #1155 from dsnopek/callable-mp
Implement `callable_mp()` and `callable_mp_static()`
Diffstat (limited to 'test/src/example.cpp')
-rw-r--r--test/src/example.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/test/src/example.cpp b/test/src/example.cpp
index 800f5ed..759cc4f 100644
--- a/test/src/example.cpp
+++ b/test/src/example.cpp
@@ -163,6 +163,12 @@ void Example::_bind_methods() {
ClassDB::bind_method(D_METHOD("test_variant_call", "variant"), &Example::test_variant_call);
+ ClassDB::bind_method(D_METHOD("test_callable_mp"), &Example::test_callable_mp);
+ ClassDB::bind_method(D_METHOD("test_callable_mp_ret"), &Example::test_callable_mp_ret);
+ ClassDB::bind_method(D_METHOD("test_callable_mp_retc"), &Example::test_callable_mp_retc);
+ ClassDB::bind_method(D_METHOD("test_callable_mp_static"), &Example::test_callable_mp_static);
+ ClassDB::bind_method(D_METHOD("test_callable_mp_static_ret"), &Example::test_callable_mp_static_ret);
+
ClassDB::bind_method(D_METHOD("test_bitfield", "flags"), &Example::test_bitfield);
ClassDB::bind_method(D_METHOD("test_rpc", "value"), &Example::test_rpc);
@@ -349,6 +355,64 @@ int Example::test_vector_ops() const {
return ret;
}
+Callable Example::test_callable_mp() {
+ return callable_mp(this, &Example::unbound_method1);
+}
+
+Callable Example::test_callable_mp_ret() {
+ return callable_mp(this, &Example::unbound_method2);
+}
+
+Callable Example::test_callable_mp_retc() const {
+ return callable_mp(this, &Example::unbound_method3);
+}
+
+Callable Example::test_callable_mp_static() const {
+ return callable_mp_static(&Example::unbound_static_method1);
+}
+
+Callable Example::test_callable_mp_static_ret() const {
+ return callable_mp_static(&Example::unbound_static_method2);
+}
+
+void Example::unbound_method1(Object *p_object, String p_string, int p_int) {
+ String test = "unbound_method1: ";
+ test += p_object->get_class();
+ test += " - " + p_string;
+ emit_custom_signal(test, p_int);
+}
+
+String Example::unbound_method2(Object *p_object, String p_string, int p_int) {
+ String test = "unbound_method2: ";
+ test += p_object->get_class();
+ test += " - " + p_string;
+ test += " - " + itos(p_int);
+ return test;
+}
+
+String Example::unbound_method3(Object *p_object, String p_string, int p_int) const {
+ String test = "unbound_method3: ";
+ test += p_object->get_class();
+ test += " - " + p_string;
+ test += " - " + itos(p_int);
+ return test;
+}
+
+void Example::unbound_static_method1(Example *p_object, String p_string, int p_int) {
+ String test = "unbound_static_method1: ";
+ test += p_object->get_class();
+ test += " - " + p_string;
+ p_object->emit_custom_signal(test, p_int);
+}
+
+String Example::unbound_static_method2(Object *p_object, String p_string, int p_int) {
+ String test = "unbound_static_method2: ";
+ test += p_object->get_class();
+ test += " - " + p_string;
+ test += " - " + itos(p_int);
+ return test;
+}
+
int Example::test_tarray_arg(const TypedArray<int64_t> &p_array) {
int sum = 0;
for (int i = 0; i < p_array.size(); i++) {