Engee documentation

Processing of operating system options

When writing cross-platform applications or libraries, it is often necessary to take into account the differences between operating systems. For such cases, you can use the variable Sys.KERNEL. The Sys module has several functions that simplify this task, such as isunix, islinux, isapple, isbsd, isfreebsd, and iswindows. They can be used as follows.

if Sys.iswindows()
    windows_specific_thing(a)
end

Note that islinux', `isapple and isfreebsd' are mutually exclusive child suites of `isunix. In addition, there is a macro @static that allows you to use these functions, hiding invalid code under certain conditions, as shown in the following examples.

Simple blocks:

ccall((@static Sys.iswindows() ? :_fopen : :fopen), ...)

Complex blocks:

@static if Sys.islinux()
    linux_specific_thing(a)
elseif Sys.isapple()
    apple_specific_thing(a)
else
    generic_thing(a)
end

When using nested conditions, it is necessary to repeat @static at each level (it is not necessary to use parentheses, but it is recommended for readability):

@static Sys.iswindows() ? :a : (@static Sys.isapple() ? :b : :c)