Skip to content

Preprocessor Functions

Vihan edited this page Dec 8, 2018 · 2 revisions

VSL has a diet preprocessor that you can access using functions prefixed with #.

#typeName(<expression>)

Internally replaced with a string which is the name of the type that <expression> resolved to. This returns the static type not the dynamic type. Meaning if you have an instance of String cast as an Equatable, it will return Equatable. If you want specific names you'll need to use Reflect<Equatable>(instanceType: myEquatableValue).typeName which will generate RTTI for all types.

Example:

print(#typeName(1)) // Resolves to 'Int32'

#position

Evaluates to a tuple with the signature:

(source: String, line: Int)

where line is a one-indexed number indicating the line number that the preprocessor directive was found. The source is a string which represents the stream which the preprocessor token was found. This is likely the source file but maybe another token such as <stdin>.

Example:

// example.vsl
print(#position.source + ":" + #position.line)
$ vsl < example.vsl
<stdin>:2