mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
scanner: add support for @VMOD_FILE
This commit is contained in:
26
doc/docs.md
26
doc/docs.md
@@ -1622,6 +1622,32 @@ $if debug {
|
||||
If you want an `if` to be evaluated at compile time it must be prefixed with a `$` sign. Right now it can only be used to detect
|
||||
an OS or a `-debug` compilation option.
|
||||
|
||||
## 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:
|
||||
```v
|
||||
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:
|
||||
```v
|
||||
import v.vmod
|
||||
vm := vmod.decode( @VMOD_FILE ) or { panic(err) }
|
||||
eprintln('$vm.name $vm.version\n $vm.description')
|
||||
```
|
||||
|
||||
## Reflection via codegen
|
||||
|
||||
Having built-in JSON support is nice, but V also allows you to create efficient
|
||||
|
Reference in New Issue
Block a user