| 1 | struct ValueMenu { |
| 2 | name string |
| 3 | } |
| 4 | |
| 5 | fn (mut v ValueMenu) resp(resp []u8) { |
| 6 | println('menu ${v.name} ${resp}') |
| 7 | } |
| 8 | |
| 9 | fn value_resp[T](mut t T, r []u8) { |
| 10 | $if T is $array { |
| 11 | value_array_resp(mut t, r) |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | fn value_array_resp[T](mut t T, r []u8) { |
| 16 | $if T is []ValueMenu { |
| 17 | for _, mut i in t { // mut i -> C error |
| 18 | i.resp(r) |
| 19 | } |
| 20 | for i := 0; i < t.len; i++ { // WORKAROUND |
| 21 | t[i].resp(r) |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | struct Colors { |
| 27 | mut: |
| 28 | normal []ValueMenu = [ValueMenu{'blink'}, ValueMenu{'hue'}] |
| 29 | } |
| 30 | |
| 31 | fn (c &Colors) resp(resp []u8) { |
| 32 | $for f in c.fields { |
| 33 | mut m := c.$(f.name) |
| 34 | value_resp(mut m, resp) |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | fn test_main() { |
| 39 | colors := &Colors{} |
| 40 | colors.resp([u8(0), 1, 2]) |
| 41 | assert true |
| 42 | } |
| 43 | |