diff options
| author | Дмитрий Сальников <salnikov.mine@yandex.ru> | 2022-12-08 08:34:19 +0300 |
|---|---|---|
| committer | DmitriySalnikov <salnikov.mine@yandex.ru> | 2023-01-20 21:10:03 +0300 |
| commit | 6528c7177fa96bfcc81805e97a0a03290816cb51 (patch) | |
| tree | 8a9ea13683e5e5f37a6392bbc2f7d6cc0aee0db4 /test/src | |
| parent | 860182fe010dea847726d309bf615927e019a8d2 (diff) | |
| download | redot-cpp-6528c7177fa96bfcc81805e97a0a03290816cb51.tar.gz | |
Fixed variant casting for enum and bitfield
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/example.cpp | 11 | ||||
| -rw-r--r-- | test/src/example.h | 15 |
2 files changed, 25 insertions, 1 deletions
diff --git a/test/src/example.cpp b/test/src/example.cpp index dec8f57..f0fce6c 100644 --- a/test/src/example.cpp +++ b/test/src/example.cpp @@ -126,6 +126,8 @@ void Example::_bind_methods() { ClassDB::bind_method(D_METHOD("test_string_ops"), &Example::test_string_ops); ClassDB::bind_method(D_METHOD("test_vector_ops"), &Example::test_vector_ops); + ClassDB::bind_method(D_METHOD("test_bitfield", "flags"), &Example::test_bitfield); + ClassDB::bind_method(D_METHOD("def_args", "a", "b"), &Example::def_args, DEFVAL(100), DEFVAL(200)); ClassDB::bind_static_method("Example", D_METHOD("test_static", "a", "b"), &Example::test_static); @@ -169,7 +171,11 @@ void Example::_bind_methods() { BIND_ENUM_CONSTANT(FIRST); BIND_ENUM_CONSTANT(ANSWER_TO_EVERYTHING); + BIND_BITFIELD_FLAG(FLAG_ONE); + BIND_BITFIELD_FLAG(FLAG_TWO); + BIND_CONSTANT(CONSTANT_WITHOUT_ENUM); + BIND_ENUM_CONSTANT(OUTSIDE_OF_CLASS); } Example::Example() { @@ -304,6 +310,11 @@ Dictionary Example::test_dictionary() const { return dict; } +BitField<Example::Flags> Example::test_bitfield(BitField<Flags> flags) { + UtilityFunctions::print(" Got BitField: ", String::num(flags)); + return flags; +} + // Properties. void Example::set_custom_position(const Vector2 &pos) { custom_position = pos; diff --git a/test/src/example.h b/test/src/example.h index 2d4a6b0..afde0f7 100644 --- a/test/src/example.h +++ b/test/src/example.h @@ -75,6 +75,11 @@ public: ANSWER_TO_EVERYTHING = 42, }; + enum Flags { + FLAG_ONE = 1, + FLAG_TWO = 2, + }; + enum { CONSTANT_WITHOUT_ENUM = 314, }; @@ -104,6 +109,8 @@ public: String test_string_ops() const; int test_vector_ops() const; + BitField<Flags> test_bitfield(BitField<Flags> flags); + // Property. void set_custom_position(const Vector2 &pos); Vector2 get_custom_position() const; @@ -117,7 +124,13 @@ public: virtual bool _has_point(const Vector2 &point) const override; }; -VARIANT_ENUM_CAST(Example, Constants); +VARIANT_ENUM_CAST(Example::Constants); +VARIANT_BITFIELD_CAST(Example::Flags); + +enum EnumWithoutClass { + OUTSIDE_OF_CLASS = 512 +}; +VARIANT_ENUM_CAST(EnumWithoutClass); class ExampleVirtual : public Object { GDCLASS(ExampleVirtual, Object); |
