Skip to content

Instantly share code, notes, and snippets.

@Zbizu
Last active December 21, 2024 13:13
Show Gist options
  • Save Zbizu/43df621b3cd0dc460a76f7fe5aa87f30 to your computer and use it in GitHub Desktop.
Save Zbizu/43df621b3cd0dc460a76f7fe5aa87f30 to your computer and use it in GitHub Desktop.
operating system (OS) detection in Lua
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
@Kein
Copy link

Kein commented Dec 21, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment