Fixed variant casting for enum and bitfield
This commit is contained in:
committed by
DmitriySalnikov
parent
860182fe01
commit
6528c7177f
@@ -73,5 +73,11 @@ func _ready():
|
||||
prints(" ANSWER_TO_EVERYTHING", $Example.ANSWER_TO_EVERYTHING)
|
||||
prints(" CONSTANT_WITHOUT_ENUM", $Example.CONSTANT_WITHOUT_ENUM)
|
||||
|
||||
prints("BitFields")
|
||||
prints(" FLAG_ONE", Example.FLAG_ONE)
|
||||
prints(" FLAG_TWO", Example.FLAG_TWO)
|
||||
prints(" returned BitField", $Example.test_bitfield(0))
|
||||
prints(" returned BitField", $Example.test_bitfield(Example.FLAG_ONE | Example.FLAG_TWO))
|
||||
|
||||
func _on_Example_custom_signal(signal_name, value):
|
||||
prints("Example emitted:", signal_name, value)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user