aboutsummaryrefslogtreecommitdiff
path: root/code
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2016-10-16 21:31:06 +0100
committerGinger Bill <bill@gingerbill.org>2016-10-16 21:31:06 +0100
commita675d3f94d2c10ce6e50b88c6c39b36c746a4d2a (patch)
tree5ef34075438257fea6ef161e90ac403fd95663fd /code
parentb9719df0ad97eea1ba67525a9ab1d3c89e95ee8c (diff)
union_cast
Diffstat (limited to 'code')
-rw-r--r--code/demo.odin22
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)
}