raz / conform / run / RecordConst.raz

34 lines · 1.1 KiB · raw · history · last change 264716cb

1module RecordConst;
2import Out;
3type
4 Act = (quit, focus, spawn);
5 Rule = record cls: []const U8; tag: INT; float: BOOL; end;
6 Key = record mods: U8; sym: U32; act: Act; arg: [8]U8; run: proc(n: INT); end;
7const
8 Rules: [3]Rule = [{cls: "firefox", tag: 2}, {cls: "mpv", float: true}, {}];
9 Nums: [3]I64 = [10, 20, 30];
10 Lists: [2][]const I64 = [Nums, Nums];
11 Home: Rule = {cls: "home", tag: 7};
12 Grid: [2][2]U8 = [[1, 2], [3, 4]];
13proc hello(n: INT);
14begin
15 Out.str("hello "); Out.int(n); Out.ln;
16end;
17const Keys: [2]Key = [{mods: 4, sym: 113, act: quit, arg: "bye", run: hello}, {act: spawn, run: nil}];
18proc main*;
19var i: INT; r: Rule;
20begin
21 for i := 0 to LEN(Rules) - 1 do
22 Out.str(Rules[i].cls); Out.str(" "); Out.int(Rules[i].tag); Out.str(" ");
23 if Rules[i].float then Out.str("float"); end;
24 Out.ln;
25 end;
26 Out.int(Lists[1][2]); Out.ln;
27 r := Home;
28 Out.str(r.cls); Out.int(Home.tag); Out.ln;
29 Out.int(I64(Grid[1][0])); Out.ln;
30 Out.str(Keys[0].arg[0..3]); Out.int(INT(Keys[0].sym)); Out.ln;
31 Keys[0].run(5);
32 if Keys[1].run = nil then Out.str("nil run"); Out.ln; end;
33end;
34end RecordConst.