docs: comptime method params (#22252)

This commit is contained in:
Felipe Pena 2024-09-18 10:53:16 -03:00 committed by GitHub
parent c5837e4f89
commit 13fdc724a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6065,6 +6065,30 @@ fn main() {
// test2 returns string: foo // test2 returns string: foo
``` ```
#### <h4 id="comptime-method-params">.params</h4>
You can retrieve information about struct method params.
```v
struct Test {
}
fn (t Test) foo(arg1 int, arg2 string) {
}
fn main() {
$for m in Test.methods {
$for param in m.params {
println('${typeof(param.typ).name}: ${param.name}')
}
}
}
// Output:
// int: arg1
// string: arg2
```
See [`examples/compiletime/reflection.v`](/examples/compiletime/reflection.v) See [`examples/compiletime/reflection.v`](/examples/compiletime/reflection.v)
for a more complete example. for a more complete example.