Skip to content

Core\Env::Platform

The operating system your program runs on.

Core\Env::Platform is declared in the class Core\Env. The constant Core\Env::OS is one of its cases.

The cases are Windows, Darwin (macOS), Linux, BSD, Solaris and Unknown. The value of Core\Env::OS is fixed when Novis is built, so it never changes while your program runs.

Compare Core\Env::OS with a case, for example Core\Env::OS == Core\Env::Platform::Windows. A misspelled case does not compile. To print the platform, use a match that gives a name for each case.

Examples

Is this a known platform

<?nvs
// Shows how to compare `Core\Env::OS` with a platform case.
// `Unknown` is only for a system that has no case of its own. Windows, macOS and
// Linux each have their own case, so this prints `known platform: yes`.
echo 'known platform: ', Core\Env::OS != Core\Env::Platform::Unknown ? 'yes' : 'no', "\n";
// Windows separates folders in a path with `\`. The other platforms use `/`.
string $separator = Core\Env::OS == Core\Env::Platform::Windows ? "\\" : '/';
// The separator is one character on every platform, so this prints `separator length: 1`.
echo 'separator length: ', Core\Str::length($separator), "\n";
Output
known platform: yes
separator length: 1