From 2b0878ec6de0c5c14932049cb3185ddb687d05bb Mon Sep 17 00:00:00 2001 From: Bob Nystrom Date: Sat, 21 May 2016 12:53:21 -0700 Subject: [PATCH] Platform.isWindows. --- doc/site/modules/os/platform.markdown | 4 ++++ src/module/os.wren | 2 ++ src/module/os.wren.inc | 2 ++ test/os/platform/is_windows.wren | 4 ++++ 4 files changed, 12 insertions(+) create mode 100644 test/os/platform/is_windows.wren diff --git a/doc/site/modules/os/platform.markdown b/doc/site/modules/os/platform.markdown index f4b62b5e..d92a2334 100644 --- a/doc/site/modules/os/platform.markdown +++ b/doc/site/modules/os/platform.markdown @@ -24,3 +24,7 @@ If Wren was compiled for an unknown operating system, returns "Unknown". Returns `true` if the host operating system is known to support the POSIX standard. This is true for Linux and other Unices, as well as the various Apple operating systems. + +### **isWindows** + +Returns `true` if the host operating system is some flavor of Windows. diff --git a/src/module/os.wren b/src/module/os.wren index 4e73f066..0ff63b85 100644 --- a/src/module/os.wren +++ b/src/module/os.wren @@ -1,6 +1,8 @@ class Platform { foreign static isPosix foreign static name + + static isWindows { name == "Windows" } } class Process { diff --git a/src/module/os.wren.inc b/src/module/os.wren.inc index 96cc3bf6..a1bf3485 100644 --- a/src/module/os.wren.inc +++ b/src/module/os.wren.inc @@ -3,6 +3,8 @@ static const char* osModuleSource = "class Platform {\n" " foreign static isPosix\n" " foreign static name\n" +"\n" +" static isWindows { name == \"Windows\" }\n" "}\n" "\n" "class Process {\n" diff --git a/test/os/platform/is_windows.wren b/test/os/platform/is_windows.wren new file mode 100644 index 00000000..f9016f8b --- /dev/null +++ b/test/os/platform/is_windows.wren @@ -0,0 +1,4 @@ +import "os" for Platform + +// It's just a less stringly-typed API for checking the name. +System.print(Platform.isWindows == (Platform.name == "Windows")) // expect: true