diff options
| author | Daylily-Zeleen <daylily-zeleen@foxmail.com> | 2024-04-24 22:14:33 +0800 |
|---|---|---|
| committer | Daylily-Zeleen <daylily-zeleen@foxmail.com> | 2024-05-28 22:59:37 +0800 |
| commit | 76cbc66785104756d6b37d16e8eb85dccc0497e8 (patch) | |
| tree | 54797bab01c125f8eb51d98e37a747f9cbd0fceb /test/src | |
| parent | b697ba8896e5fd0966274f00798c55a5bfed4e74 (diff) | |
| download | redot-cpp-76cbc66785104756d6b37d16e8eb85dccc0497e8.tar.gz | |
Set instance and instance binding in Wrapped constructor.
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/example.cpp | 18 | ||||
| -rw-r--r-- | test/src/example.h | 5 |
2 files changed, 22 insertions, 1 deletions
diff --git a/test/src/example.cpp b/test/src/example.cpp index 78d7062..52d2bd3 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); @@ -290,7 +292,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."); } @@ -370,6 +382,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 1af4e5f..3d178c4 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; |
