Skip to content

Preprocessor

IsaacShelton edited this page Mar 21, 2022 · 1 revision

Preprocessor

The preprocessor can be used to conditionally compile sections of code and perform basic computations

Meta Directives

Meta directives can be used to invoke the preprocessor

#if use_secret_feature
    useSecret()
#end

See meta directives for a full list of meta directives

Transcendent Values

Transcendent values are values that are used by the preprocessor and only exist at compile-time.

They can be used in combination with meta directives to interact with the preprocessor.

#if include_secret_feature
    // ...
#end

#set view_area 3.14159265 * view_radius ** 2

#unless is_posix || has_pthread
    // ...
#end

See transcendent values for more information

Granularity

The preprocessor works on an AST level, text-substitutions are not allowed.

// BAD

if(
#if use_condition_one    // BAD
    is_sky_blue          // BAD
#else                    // BAD
    is_grass_green       // BAD
#end){                   // BAD
    // This won't compile
}
// GOOD

#if use_condition_one
should bool = is_sky_blue
#else
should bool = is_grass_green
#end

if should {
    
}
Clone this wiki locally