summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/project/example.gd5
-rw-r--r--test/project/main.gd4
-rw-r--r--test/project/main.tscn4
-rw-r--r--test/src/example.cpp11
-rw-r--r--test/src/example.h4
5 files changed, 27 insertions, 1 deletions
diff --git a/test/project/example.gd b/test/project/example.gd
new file mode 100644
index 0000000..b20280a
--- /dev/null
+++ b/test/project/example.gd
@@ -0,0 +1,5 @@
+extends Example
+
+func _do_something_virtual(p_name, p_value):
+ custom_signal.emit(p_name, p_value)
+ return "Implemented"
diff --git a/test/project/main.gd b/test/project/main.gd
index 59cab6d..d2cbd26 100644
--- a/test/project/main.gd
+++ b/test/project/main.gd
@@ -241,6 +241,10 @@ func _ready():
assert_equal(new_example_ref.was_post_initialized(), true)
assert_equal(example.test_post_initialize(), true)
+ # Test a virtual method defined in GDExtension and implemented in script.
+ assert_equal(example.test_virtual_implemented_in_script("Virtual", 939), "Implemented")
+ assert_equal(custom_signal_emitted, ["Virtual", 939])
+
exit_with_status()
func _on_Example_custom_signal(signal_name, value):
diff --git a/test/project/main.tscn b/test/project/main.tscn
index 2b98e0f..1f17597 100644
--- a/test/project/main.tscn
+++ b/test/project/main.tscn
@@ -1,11 +1,13 @@
-[gd_scene load_steps=2 format=3 uid="uid://dmx2xuigcpvt4"]
+[gd_scene load_steps=3 format=3 uid="uid://dmx2xuigcpvt4"]
[ext_resource type="Script" path="res://main.gd" id="1_qesh5"]
+[ext_resource type="Script" path="res://example.gd" id="2_jju25"]
[node name="Node" type="Node"]
script = ExtResource("1_qesh5")
[node name="Example" type="Example" parent="."]
+script = ExtResource("2_jju25")
[node name="ExampleMin" type="ExampleMin" parent="Example"]
layout_mode = 0
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);