mirror of
https://github.com/godotengine/godot-cpp.git
synced 2025-12-31 01:48:45 +03:00
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.
This commit is contained in:
@@ -9,6 +9,9 @@ class TestClass:
|
||||
func _ready():
|
||||
var example: Example = $Example
|
||||
|
||||
# Timing of set instance binding.
|
||||
assert_equal(example.is_object_binding_set_by_parent_constructor(), true)
|
||||
|
||||
# Signal.
|
||||
example.emit_custom_signal("Button", 42)
|
||||
assert_equal(custom_signal_emitted, ["Button", 42])
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user