mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-23 14:14:59 -07:00
union_cast
This commit is contained in:
+17
-5
@@ -1,13 +1,25 @@
|
||||
#import "fmt.odin"
|
||||
|
||||
main :: proc() {
|
||||
Thing :: struct {
|
||||
f: f32
|
||||
a: any
|
||||
Entity :: union {
|
||||
Apple: int
|
||||
Banana: f32
|
||||
Goat: struct {
|
||||
x, y: int
|
||||
z, w: f32
|
||||
}
|
||||
}
|
||||
t := Thing{1, "Hello"}
|
||||
|
||||
a := 123 as Entity.Apple
|
||||
e: Entity = a
|
||||
fmt.println(a)
|
||||
|
||||
fmt.printf("Here % %\n", 123, 2.0)
|
||||
if apple, ok := ^e union_cast ^Entity.Apple; ok {
|
||||
apple^ = 321
|
||||
e = apple^
|
||||
}
|
||||
|
||||
apple, ok := e union_cast Entity.Apple
|
||||
fmt.println(apple)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user