3

我正在寻找类似于 python 的 sys.platform 的东西,它返回 'linux'、'windows' 等,甚至更好,比如 python 的平台模块,它为您提供操作系统、发行版、发布版本等。

4

1 回答 1

9
when defined windows:
  echo "I'm on Windows!"
elif defined linux:
  echo "I'm on Linux!"
else:
  echo "I'm on some other platform!"

when defined x86:
  echo "x86 specific code!"
elif defined amd64:
  echo "amd64 specific code!"
else:
  echo "generic code!"

when (NimMajor,NimMinor,NimPatch) > (0,10,2):
  echo "Such a modern Nim version!"

echo "OS: ", hostOS, ", CPU: ", hostCPU, ", cpuEndian: ", cpuEndian, ", NimVersion: ", NimVersion

这在我的系统上打印:

I'm on Linux!
amd64 specific code!
Such a modern Nim version!
OS: linux, CPU: amd64, cpuEndian: littleEndian, NimVersion: 0.10.3
于 2015-02-18T00:40:03.590 回答