Handle enums correctly with printf

This commit is contained in:
Ginger Bill
2017-01-08 23:19:50 +00:00
parent ff473e8342
commit c29d433e38
3 changed files with 112 additions and 59 deletions

View File

@@ -1,31 +1,10 @@
#import "fmt.odin";
main :: proc() {
using Type_Info;
is_type_integer :: proc(info: ^Type_Info) -> bool {
if info == nil {
return false;
}
match type i : type_info_base(info) {
case Integer:
return true;
}
return false;
}
ti := type_info_base(type_info(Allocator_Mode));
match type e : ti {
case Enum:
is_int := is_type_integer(e.base);
for i : 0..<e.names.count {
name := e.names[i];
value := e.values[i];
if is_int {
fmt.printf("%s - %d\n", name, value.i);
} else {
fmt.printf("%s - %f\n", name, value.f);
}
}
Fruit :: enum f32 {
Apple = 123,
Pear = 321,
Tomato,
}
fmt.printf("%s = %f\n", Fruit.Apple, Fruit.Apple);
}