mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
docs: comptime method params (#22252)
This commit is contained in:
parent
c5837e4f89
commit
13fdc724a7
1 changed files with 25 additions and 1 deletions
26
doc/docs.md
26
doc/docs.md
|
@ -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.
|
||||||
|
|
||||||
|
@ -8040,4 +8064,4 @@ Assignment Operators
|
||||||
&= |= ^=
|
&= |= ^=
|
||||||
>>= <<= >>>=
|
>>= <<= >>>=
|
||||||
&&= ||=
|
&&= ||=
|
||||||
```
|
```
|
Loading…
Add table
Add a link
Reference in a new issue