Compile time pseudo variables

V also gives your code access to a set of pseudo string variables, that are substituted at compile time:

  • @FN => replaced with the name of the current V function
  • @MOD => replaced with the name of the current V module
  • @STRUCT => replaced with the name of the current V struct
  • @FILE => replaced with the path of the V source file
  • @LINE => replaced with the V line number where it appears (as a string).
  • @COLUMN => replaced with the column where it appears (as a string).
  • @VEXE => replaced with the path to the V compiler
  • @VHASH => replaced with the shortened commit hash of the V compiler (as a string).
  • @VMOD_FILE => replaced with the contents of the nearest v.mod file (as a string).

That allows you to do the following example, useful while debugging/logging/tracing your code:

  1. eprintln('file: ' + @FILE + ' | line: ' + @LINE + ' | fn: ' + @MOD + '.' + @FN)

Another example, is if you want to embed the version/name from v.mod inside your executable:

  1. import v.vmod
  2. vm := vmod.decode( @VMOD_FILE ) or { panic(err) }
  3. eprintln('$vm.name $vm.version\n $vm.description')