----- Original Message -----
Sent: Friday, September 26, 2014 9:20
PM
Subject: Re: Detect Windows reliably
(was: io.popen binary writecompatibility)
On 2014-09-26 1:38 PM, "Doug Currie" <doug.currie@gmail.com>
wrote:
>
> As a quick hack I've done:
>
> local path =
os.getenv('PATH')
> if path:find('C:\\Program') then
>
windows = true
> else
> windows =
false
> end
>
> There are surely better strings for
discrimination.
>
I'd look for just C:\, or see if it's possible to open C:\boot.ini (but I'm
not sure all programs are allowed to open it?)
It's technically possible for there to not be a C:\ (Windows can be
installed to any letter), but a lot of programs expect there to be. You could
try every letter just to be sure though.
That said, perhaps Lua could define a variable like _OS = "windows" (or
"linux", etc). Since the interpreter has to be compiled for each OS anyway,
you'd just change the string constant. (for eg an embedded environment it
could be nil.) Or this could even be in the os library (os.name?)
Alternatively there are probably other environment variables you can check
for the presence/lack of, like $PS1, $HOME,
$WINROOT...