mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
gen: compile time for (methods and fields) (#5957)
This commit is contained in:
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
|
||||
}
|
Reference in New Issue
Block a user