| 1 | struct App {} |
| 2 | |
| 3 | fn (mut app App) method_one() string { |
| 4 | return '1' |
| 5 | } |
| 6 | |
| 7 | fn (mut app App) method_two() string { |
| 8 | return '2' |
| 9 | } |
| 10 | |
| 11 | fn reflect_call(method_name string) string { |
| 12 | a := App{} |
| 13 | $for method in App.methods { |
| 14 | if method.name == method_name { |
| 15 | return a.$method() + '' |
| 16 | } |
| 17 | } |
| 18 | panic('Method not supported: ${method_name}') |
| 19 | } |
| 20 | |
| 21 | fn test_comptime_method_call() { |
| 22 | result := reflect_call('method_one') |
| 23 | println(result) |
| 24 | assert result == '1' |
| 25 | } |
| 26 |