Trace
Another feature of v.debug
is the possibility to add hook functions
before and after each function call.
To enable this feature, add the -d trace
switch when building or running
your code:
import v.debug
fn main() {
hook1 := debug.add_before_call(fn (fn_name string) {
println('> before ${fn_name}')
})
hook2 := debug.add_after_call(fn (fn_name string) {
println('> after ${fn_name}')
})
anon := fn () {
println('call')
}
anon()
// optionally you can remove the hooks:
debug.remove_before_call(hook1)
debug.remove_after_call(hook2)
anon()
}
$ v -d trace run example.v
> before anon
call
> after anon
call