This page has very useful information regarding platform detection:
Differentiating between windows & unix can be done by using package.config
; the first character is the folder path separator (\ on windows, / on unix).
Robin wrote:It's not water-tight, I think there are some Linux distributions that create those folder. How about running "uname" first? If prints "Linux", it's Linux, if it prints "Darwin" it's OS X. The thing is, I'm not sure how to redirect standard output in Lua (other than writing it to a temporary file and reading that).
The capturing output thing can be done with io.popen
, according to one of the links in PlatformDetection
This should detect Windows / Linux / Darwin (and probably other unix-likes, such as OpenBSD or Windows+MingGW):
Code: Select all
function platform() -- returns 'Windows', 'Linux' or 'Darwin'
if package.config:sub(1,1) == '\\' then return 'Windows' end
return io.popen("uname -s"):read("*l")
I know all this because I investigated about platform detection while doing my ansicolors module. I don't know the Lua-users wiki by heart.