diff options
author | David Snopek <dsnopek@gmail.com> | 2023-11-17 12:48:39 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-17 12:48:39 -0600 |
commit | 4439a4a569b641934a0e1c2320c11b5bb7c61fa7 (patch) | |
tree | 2becb52afc6e33cdacb3396af32fd2edd0c812a9 /test/src/example.cpp | |
parent | c4b7b08c917e4dd41e4a53d28660b7358e60d7b1 (diff) | |
parent | d33bd47219314e825d1130e646bc34f52fe65600 (diff) | |
download | redot-cpp-4439a4a569b641934a0e1c2320c11b5bb7c61fa7.tar.gz |
Merge pull request #1280 from dsnopek/callable-custom
Add `CallableCustom` that devs can use in their GDExtensions
Diffstat (limited to 'test/src/example.cpp')
-rw-r--r-- | test/src/example.cpp | 45 |
1 files changed, 45 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(); |