Allow method binds to take Object subclasses as arguments

As done in upstream Godot via GH-57205.

Add a test that ensures it works also for "gdextended" objects.
This commit is contained in:
Fabio Alessandrelli
2023-01-10 11:48:21 +01:00
parent 129c358a72
commit 9fd33b5cde
4 changed files with 26 additions and 3 deletions

View File

@@ -122,6 +122,7 @@ void Example::_bind_methods() {
ClassDB::bind_method(D_METHOD("test_tarray_arg", "array"), &Example::test_tarray_arg);
ClassDB::bind_method(D_METHOD("test_tarray"), &Example::test_tarray);
ClassDB::bind_method(D_METHOD("test_dictionary"), &Example::test_dictionary);
ClassDB::bind_method(D_METHOD("test_node_argument"), &Example::test_node_argument);
ClassDB::bind_method(D_METHOD("def_args", "a", "b"), &Example::def_args, DEFVAL(100), DEFVAL(200));
@@ -212,6 +213,11 @@ ExampleRef *Example::return_extended_ref() const {
return memnew(ExampleRef());
}
Example *Example::test_node_argument(Example *p_node) const {
UtilityFunctions::print(" Test node argument called with ", p_node ? String::num(p_node->get_instance_id()) : "null");
return p_node;
}
Ref<ExampleRef> Example::extended_ref_checks(Ref<ExampleRef> p_ref) const {
// This is therefor the prefered way of instancing and returning a refcounted object:
Ref<ExampleRef> ref;

View File

@@ -100,6 +100,7 @@ public:
void test_tarray_arg(const TypedArray<int64_t> &p_array);
TypedArray<Vector2> test_tarray() const;
Dictionary test_dictionary() const;
Example *test_node_argument(Example *p_node) const;
// Property.
void set_custom_position(const Vector2 &pos);