| 1 | module main |
| 2 | |
| 3 | @[heap] |
| 4 | interface IGameObject { |
| 5 | mut: |
| 6 | name string |
| 7 | parent ?&IGameObject |
| 8 | next ?&IGameObject |
| 9 | child ?&IGameObject |
| 10 | last_child ?&IGameObject |
| 11 | } |
| 12 | |
| 13 | @[heap] |
| 14 | struct GameObject implements IGameObject { |
| 15 | mut: |
| 16 | name string |
| 17 | parent ?&IGameObject |
| 18 | next ?&IGameObject |
| 19 | child ?&IGameObject |
| 20 | last_child ?&IGameObject |
| 21 | } |
| 22 | |
| 23 | fn test_main() { |
| 24 | mut v1 := &GameObject{ |
| 25 | name: 'v1' |
| 26 | } |
| 27 | v1.next = &GameObject{ |
| 28 | name: 'v2' |
| 29 | } |
| 30 | |
| 31 | mut next := v1.next |
| 32 | for { |
| 33 | if mut next != none { |
| 34 | eprintln(next.name) |
| 35 | assert next.name == 'v2' |
| 36 | next = next.next |
| 37 | } else { |
| 38 | break |
| 39 | } |
| 40 | } |
| 41 | assert next == none |
| 42 | } |
| 43 |