mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
gen: compile time for (methods and fields) (#5957)
This commit is contained in:
parent
2ccb28a93e
commit
b58b15993c
12 changed files with 510 additions and 231 deletions
45
examples/compiletime/compile-time-for.v
Normal file
45
examples/compiletime/compile-time-for.v
Normal file
|
@ -0,0 +1,45 @@
|
|||
module main
|
||||
|
||||
struct App {
|
||||
test string [test]
|
||||
mut:
|
||||
a string
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println('All functions')
|
||||
$for method in App.methods {
|
||||
$if method.@type is int {
|
||||
println('hi')
|
||||
}
|
||||
println('$method.name.len')
|
||||
println('$method.name.str')
|
||||
println('Method: $method.name')
|
||||
println('Attributes: $method.attrs')
|
||||
println('Return type: $method.ret_type')
|
||||
}
|
||||
println('All integer functions')
|
||||
$for method in App.methods {
|
||||
println('Method: $method.name')
|
||||
println('Attributes: $method.attrs')
|
||||
}
|
||||
$for field in App.fields {
|
||||
$if field.@type is string {
|
||||
println(field)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn (mut app App) method_one() {
|
||||
}
|
||||
|
||||
fn (mut app App) method_two() {
|
||||
}
|
||||
|
||||
fn (mut app App) method_three() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
fn (mut app App) method_four() int {
|
||||
return 1
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue