GDScript: Treat enum values as int and enum types as dictionary
Since enums resolve to a dictionary at runtime, calling dictionary methods on an enum type is a valid use case. This ensures this is true by adding test cases. This also makes enum values be treated as ints when used in operations.
This commit is contained in:
parent
b013c0d544
commit
ceafdf347e
6 changed files with 127 additions and 31 deletions
|
|
@ -0,0 +1,21 @@
|
|||
# Enum is equivalent to int for comparisons and operations.
|
||||
enum MyEnum {
|
||||
ZERO,
|
||||
ONE,
|
||||
TWO,
|
||||
}
|
||||
|
||||
enum OtherEnum {
|
||||
ZERO,
|
||||
ONE,
|
||||
TWO,
|
||||
}
|
||||
|
||||
func test():
|
||||
print(MyEnum.ZERO == OtherEnum.ZERO)
|
||||
print(MyEnum.ZERO == 1)
|
||||
print(MyEnum.ZERO != OtherEnum.ONE)
|
||||
print(MyEnum.ZERO != 0)
|
||||
|
||||
print(MyEnum.ONE + OtherEnum.TWO)
|
||||
print(2 - MyEnum.ONE)
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
GDTEST_OK
|
||||
true
|
||||
false
|
||||
true
|
||||
false
|
||||
3
|
||||
1
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
enum MyEnum {
|
||||
ZERO,
|
||||
ONE,
|
||||
TWO,
|
||||
}
|
||||
|
||||
func test():
|
||||
for key in MyEnum.keys():
|
||||
prints(key, MyEnum[key])
|
||||
|
||||
# https://github.com/godotengine/godot/issues/55491
|
||||
for key in MyEnum:
|
||||
prints(key, MyEnum[key])
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
GDTEST_OK
|
||||
ZERO 0
|
||||
ONE 1
|
||||
TWO 2
|
||||
ZERO 0
|
||||
ONE 1
|
||||
TWO 2
|
||||
Loading…
Add table
Add a link
Reference in a new issue