diff options
| author | David Snopek <dsnopek@gmail.com> | 2023-10-21 18:32:45 -0500 |
|---|---|---|
| committer | David Snopek <dsnopek@gmail.com> | 2023-11-06 00:09:06 -0600 |
| commit | d33bd47219314e825d1130e646bc34f52fe65600 (patch) | |
| tree | a3807017aeaefffa6bcda77f1fcebef436de4047 /test/src | |
| parent | 2dfe7929de31e52258380e414cce6978c1c94344 (diff) | |
| download | redot-cpp-d33bd47219314e825d1130e646bc34f52fe65600.tar.gz | |
Add `CallableCustom` that devs can use in their GDExtensions
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/example.cpp | 45 | ||||
| -rw-r--r-- | test/src/example.h | 1 |
2 files changed, 46 insertions, 0 deletions
diff --git a/test/src/example.cpp b/test/src/example.cpp index dd58f37..2b8bef6 100644 --- a/test/src/example.cpp +++ b/test/src/example.cpp @@ -15,6 +15,46 @@ using namespace godot; +class MyCallableCustom : public CallableCustom { +public: + virtual uint32_t hash() const { + return 27; + } + + virtual String get_as_text() const { + return "<MyCallableCustom>"; + } + + static bool compare_equal_func(const CallableCustom *p_a, const CallableCustom *p_b) { + return p_a == p_b; + } + + virtual CompareEqualFunc get_compare_equal_func() const { + return &MyCallableCustom::compare_equal_func; + } + + static bool compare_less_func(const CallableCustom *p_a, const CallableCustom *p_b) { + return (void *)p_a < (void *)p_b; + } + + virtual CompareLessFunc get_compare_less_func() const { + return &MyCallableCustom::compare_less_func; + } + + bool is_valid() const { + return true; + } + + virtual ObjectID get_object() const { + return ObjectID(); + } + + virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, GDExtensionCallError &r_call_error) const { + r_return_value = "Hi"; + r_call_error.error = GDEXTENSION_CALL_OK; + } +}; + void ExampleRef::set_id(int p_id) { id = p_id; } @@ -168,6 +208,7 @@ void Example::_bind_methods() { 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_custom_callable"), &Example::test_custom_callable); ClassDB::bind_method(D_METHOD("test_bitfield", "flags"), &Example::test_bitfield); @@ -378,6 +419,10 @@ Callable Example::test_callable_mp_static_ret() const { return callable_mp_static(&Example::unbound_static_method2); } +Callable Example::test_custom_callable() const { + return Callable(memnew(MyCallableCustom)); +} + void Example::unbound_method1(Object *p_object, String p_string, int p_int) { String test = "unbound_method1: "; test += p_object->get_class(); diff --git a/test/src/example.h b/test/src/example.h index 200c970..388cc8c 100644 --- a/test/src/example.h +++ b/test/src/example.h @@ -143,6 +143,7 @@ public: Callable test_callable_mp_retc() const; Callable test_callable_mp_static() const; Callable test_callable_mp_static_ret() const; + Callable test_custom_callable() const; void unbound_method1(Object *p_object, String p_string, int p_int); String unbound_method2(Object *p_object, String p_string, int p_int); |
