Qore supports conditional parsing with parse defines similar to the C/C++ preprocessor. In the current version of Qore, the implementation is very simple; only the following parse directives are supported: %define, %else, %endif, %ifdef, and %ifndef.
Basically, the above allow for the existence (or lack thereof) of a parse define to affect which code is parsed into the program at parse time.
Parse defines are defined on the command-line (or through the C++ API when executed in embedded code), as well as created automatically based on sytem options; all library options (if the option is True, then it is defined as True, if the option is False, then it is not defined at all).
Note that Unix is defined on all Unix platforms (also on Cygwin), while Windows is defined on native Windows ports (but not on Cygwin, as this is treated as Unix when compiling, as all Unix features are available).
Additionally, the following options are defined in every program (however they are not yet useful when parsing as the value of parse options cannot be used yet at parse time; only the existence or lack thereof can affect parsing in this version of Qore when parsing at least):
QoreVersionString: Version string for the Qore libraryQoreVersionMajor: Major version for the Qore libraryQoreVersionMinor: Minor version for the Qore libraryQoreVersionSub: Sub version for the Qore libraryQoreVersionBuild: Build version for the Qore libraryQoreVersionBits: 32 or 64 depending on the library targetQorePlatformCPU: The CPU targeted by the libraryQorePlatformOS: The OS targeted by the libraryAdditionally, only if the Qore library was compiled with debugging support, the following parse define is present (otherwise it is not defined):
QoreDebug: TrueHere is an example of using parse defines in a program:
%ifndef HAVE_TERMIOS
printf("This program requires UNIX TermIOS features to be present; it does not run on platforms without this feature (current platform: %s); exiting...\n", Qore::PlatformOS);
exit(1);
%endifFurthermore, parse defines can be manipulated in embedded code using the following functions:
There are no comments yet