Files
sx/examples/03-structs.sx
2026-02-09 20:09:39 +02:00

37 lines
773 B
Plaintext

#import "modules/std.sx";
Vec4 :: struct {
x, y, z, w: f32;
}
Complex :: struct {
foo : union {
S: s32;
B: struct {
val: string;
};
} = .B.{val = "hello"};
}
main :: () {
v1 : Vec4 = .{ 1, 2, 3, 0};
v2 := Vec4.{ 4, 1, 1, 3};
v3 := Vec4.{ w=0, x=2, y=3, z=4};
z := 5.0; // z is f32
w := 6.0; // w is f32
v4 := Vec4.{ y=3, x=9, w, z};
v4.y = 0;
print("v1: {}\nv2: {}\nv3: {}\nv4: {}\n", v1, v2, v3, v4);
complex : Complex = .{};
print("\n{}\n", complex);
}
// ** stdout **
//v1: Vec4{x:1.0, y:2.0, z:3.0, w:0.0}
//v2: Vec4{x:4.0, y:1.0, z:1.0, w:3.0}
//v3: Vec4{x:2.0, y:3.0, z:4.0, w:0.0}
//v4: Vec4{x:9.0, y:3.0, z:5.0, w:6.0}
//
//Complex{foo: .B(Complex.foo.B{val: hello})}