Last active
December 21, 2024 13:13
-
-
Save Zbizu/43df621b3cd0dc460a76f7fe5aa87f30 to your computer and use it in GitHub Desktop.
operating system (OS) detection in Lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getOS() | |
-- ask LuaJIT first | |
if jit then | |
return jit.os | |
end | |
-- Unix, Linux variants | |
local fh,err = assert(io.popen("uname -o 2>/dev/null","r")) | |
if fh then | |
osname = fh:read() | |
end | |
return osname or "Windows" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a terrible solution for CLI apps, it re-opens and re-initializes conout 4-5 times in a row, leading not just to a seizure-flashing console windows, but also to all kinds of bugs down the road