summaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorDavid Snopek <dsnopek@gmail.com>2024-01-30 11:25:25 -0600
committerDavid Snopek <dsnopek@gmail.com>2024-02-12 13:30:07 -0600
commit8fbb7cf79535a2b382d57ce2a094d4cbee316fd1 (patch)
tree3b3ea3c4c80911752073ba50920600a348ab81de /test/src
parent36847f6af0be548bae96429fa84d59f407b51582 (diff)
downloadredot-cpp-8fbb7cf79535a2b382d57ce2a094d4cbee316fd1.tar.gz
Allow GDExtensions to register virtual methods and call them on scripts
Diffstat (limited to 'test/src')
-rw-r--r--test/src/example.cpp11
-rw-r--r--test/src/example.h4
2 files changed, 15 insertions, 0 deletions
diff --git a/test/src/example.cpp b/test/src/example.cpp
index 5372d70..53d11f4 100644
--- a/test/src/example.cpp
+++ b/test/src/example.cpp
@@ -230,6 +230,9 @@ void Example::_bind_methods() {
ClassDB::bind_method(D_METHOD("callable_bind"), &Example::callable_bind);
ClassDB::bind_method(D_METHOD("test_post_initialize"), &Example::test_post_initialize);
+ GDVIRTUAL_BIND(_do_something_virtual, "name", "value");
+ ClassDB::bind_method(D_METHOD("test_virtual_implemented_in_script"), &Example::test_virtual_implemented_in_script);
+
ClassDB::bind_static_method("Example", D_METHOD("test_static", "a", "b"), &Example::test_static);
ClassDB::bind_static_method("Example", D_METHOD("test_static2"), &Example::test_static2);
@@ -626,3 +629,11 @@ void Example::_input(const Ref<InputEvent> &event) {
emit_custom_signal(String("_input: ") + key_event->get_key_label(), key_event->get_unicode());
}
}
+
+String Example::test_virtual_implemented_in_script(const String &p_name, int p_value) {
+ String ret;
+ if (GDVIRTUAL_CALL(_do_something_virtual, p_name, p_value, ret)) {
+ return ret;
+ }
+ return "Unimplemented";
+}
diff --git a/test/src/example.h b/test/src/example.h
index c86a51f..1c57720 100644
--- a/test/src/example.h
+++ b/test/src/example.h
@@ -24,6 +24,7 @@
#include <godot_cpp/variant/variant.hpp>
#include <godot_cpp/core/binder_common.hpp>
+#include <godot_cpp/core/gdvirtual.gen.inc>
using namespace godot;
@@ -181,6 +182,9 @@ public:
// Virtual function override (no need to bind manually).
virtual bool _has_point(const Vector2 &point) const override;
virtual void _input(const Ref<InputEvent> &event) override;
+
+ GDVIRTUAL2R(String, _do_something_virtual, String, int);
+ String test_virtual_implemented_in_script(const String &p_name, int p_value);
};
VARIANT_ENUM_CAST(Example::Constants);