open-papyrus / papyrus-compiler

Open-source compiler for the Papyrus scripting language of Bethesda games.
https://open-papyrus.github.io/docs/papyrus-compiler/Introduction.html
MIT License
25 stars 3 forks source link

Preprocessor directives #6

Open Osmosis-Wrench opened 2 years ago

Osmosis-Wrench commented 2 years ago

Pre-processor statements (like the c++ style #ifdef) for code blocks would be useful. Would allow for something like:

#ifdef debug
    my_logging_functions_here()
#endif
erri120 commented 2 years ago

Papyrus already has the DebugOnly and BetaOnly flags for functions:

Debug-only functions may be defined by adding "DebugOnly" to the end of the function definition line. Any calls to these functions will be removed in release script builds. Beta-only functions may be defined by adding "BetaOnly" to the end of the function definition line. Any calls to these functions will be removed in final script builds.

(Source)

However only the F04 Compiler supports these flags:

Release flag This setting only applies to Fallout 4. It instructs Papyrus compiler to use release mode ("-r"), which removes all debugOnly function calls and optimizes the output, supposedly reducing the output size. Final flag This setting only applies to Fallout 4. It instructs Papyrus compiler to use final mode ("-final"), which removes all betaOnly function calls and optimizes the output, supposedly reducing the output size.

(Source)

The new compiler will support these flags regardless of game so you can happily log stuff in debug mode. That makes the use-cases of preprocessor directives rather limiting.