summaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorDavid Snopek <dsnopek@gmail.com>2024-06-14 09:39:46 -0500
committerGitHub <noreply@github.com>2024-06-14 09:39:46 -0500
commit5d8f80bc5578a2312d271d854745a172dad56501 (patch)
tree5edad0345eb3f085ba44ffcfebef705500520ed0 /test/src
parentee9acbcf109486eec3827d84ff033387762bccb7 (diff)
parent76cbc66785104756d6b37d16e8eb85dccc0497e8 (diff)
downloadredot-cpp-5d8f80bc5578a2312d271d854745a172dad56501.tar.gz
Merge pull request #1446 from Daylily-Zeleen/daylily-zeleen/set_instance_and_instance_biding_in_Wrapped_constructor
Set instance and instance binding in `Wrapped` constructor.
Diffstat (limited to 'test/src')
-rw-r--r--test/src/example.cpp18
-rw-r--r--test/src/example.h5
2 files changed, 22 insertions, 1 deletions
diff --git a/test/src/example.cpp b/test/src/example.cpp
index c445268..a0a0da2 100644
--- a/test/src/example.cpp
+++ b/test/src/example.cpp
@@ -193,6 +193,8 @@ void Example::_bind_methods() {
ClassDB::bind_method(D_METHOD("return_extended_ref"), &Example::return_extended_ref);
ClassDB::bind_method(D_METHOD("extended_ref_checks", "ref"), &Example::extended_ref_checks);
+ ClassDB::bind_method(D_METHOD("is_object_binding_set_by_parent_constructor"), &Example::is_object_binding_set_by_parent_constructor);
+
ClassDB::bind_method(D_METHOD("test_array"), &Example::test_array);
ClassDB::bind_method(D_METHOD("test_tarray_arg", "array"), &Example::test_tarray_arg);
ClassDB::bind_method(D_METHOD("test_tarray"), &Example::test_tarray);
@@ -291,7 +293,17 @@ void Example::_bind_methods() {
BIND_ENUM_CONSTANT(OUTSIDE_OF_CLASS);
}
-Example::Example() {
+bool Example::has_object_instance_binding() const {
+ return internal::gdextension_interface_object_get_instance_binding(_owner, internal::token, nullptr);
+}
+
+Example::Example() :
+ object_instance_binding_set_by_parent_constructor(has_object_instance_binding()) {
+ // Test conversion, to ensure users can use all parent calss functions at this time.
+ // It would crash if instance binding still not be initialized.
+ Variant v = Variant(this);
+ Object *o = (Object *)v;
+
//UtilityFunctions::print("Constructor.");
}
@@ -371,6 +383,10 @@ void Example::emit_custom_signal(const String &name, int value) {
emit_signal("custom_signal", name, value);
}
+bool Example::is_object_binding_set_by_parent_constructor() const {
+ return object_instance_binding_set_by_parent_constructor;
+}
+
Array Example::test_array() const {
Array arr;
diff --git a/test/src/example.h b/test/src/example.h
index 9fa2b07..1dcefe3 100644
--- a/test/src/example.h
+++ b/test/src/example.h
@@ -82,6 +82,9 @@ private:
Vector2 dprop[3];
int last_rpc_arg = 0;
+ const bool object_instance_binding_set_by_parent_constructor;
+ bool has_object_instance_binding() const;
+
public:
// Constants.
enum Constants {
@@ -120,6 +123,8 @@ public:
void emit_custom_signal(const String &name, int value);
int def_args(int p_a = 100, int p_b = 200);
+ bool is_object_binding_set_by_parent_constructor() const;
+
Array test_array() const;
int test_tarray_arg(const TypedArray<int64_t> &p_array);
TypedArray<Vector2> test_tarray() const;