diff options
| author | Ginger Bill <bill@gingerbill.org> | 2016-10-16 21:31:06 +0100 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2016-10-16 21:31:06 +0100 |
| commit | a675d3f94d2c10ce6e50b88c6c39b36c746a4d2a (patch) | |
| tree | 5ef34075438257fea6ef161e90ac403fd95663fd /code | |
| parent | b9719df0ad97eea1ba67525a9ab1d3c89e95ee8c (diff) | |
union_cast
Diffstat (limited to 'code')
| -rw-r--r-- | code/demo.odin | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/code/demo.odin b/code/demo.odin index 3011b745a..78cee21d4 100644 --- a/code/demo.odin +++ b/code/demo.odin @@ -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) } |