| 1 | module RecordConst; |
| 2 | import Out; |
| 3 | type |
| 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; |
| 7 | const |
| 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]]; |
| 13 | proc hello(n: INT); |
| 14 | begin |
| 15 | Out.str("hello "); Out.int(n); Out.ln; |
| 16 | end; |
| 17 | const Keys: [2]Key = [{mods: 4, sym: 113, act: quit, arg: "bye", run: hello}, {act: spawn, run: nil}]; |
| 18 | proc main*; |
| 19 | var i: INT; r: Rule; |
| 20 | begin |
| 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; |
| 33 | end; |
| 34 | end RecordConst. |