Last active
April 29, 2022 12:04
-
-
Save Rabios/1420e60531093c37f43ffa55eef521ec to your computer and use it in GitHub Desktop.
Detect some operating systems and CPU architecture via Lua
This file contains 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
-- Written by Rabia Alhaffar in June 14, 2021 | |
-- Simple script to detect some operating systems and CPU architecture via Lua! ;) | |
-- Updated: June 14, 2021 | |
-- Also, I would thank NickWilde263 and Nameless on GitHub for their suggestions! <3 | |
-- https://github.com/NickWilde263 | |
-- https://github.com/truemedian | |
local sys = { | |
arch = "UNKNOWN", | |
os = "UNKNOWN" | |
} | |
if string.match(package.path, "/storage/emulated/0/") or string.match(package.cpath, "/data/app/") then | |
sys.os = "android" | |
elseif string.match(package.path, "/var/mobile/") then | |
sys.os = "ios" | |
elseif string.match(package.path, "\\") then | |
sys.os = "windows" | |
else | |
local sysf = io.popen("uname -a") | |
local linux_uname = sysf:read("*a") | |
if string.match(linux_uname, "Darwin") then | |
sys.os = "macos" | |
elseif string.match(linux_uname, "raspberrypi") then | |
sys.os = "rpi" | |
else | |
sys.os = "linux" | |
end | |
sysf:close() | |
end | |
if sys.os == "windows" then | |
if (string.match(os.getenv("PROCESSOR_ARCHITECTURE"), "x86")) then | |
sys.arch = "x86" | |
elseif (string.match(os.getenv("PROCESSOR_ARCHITECTURE"), "ARM")) then | |
sys.arch = "arm32" | |
elseif (string.match(os.getenv("PROCESSOR_ARCHITECTURE"), "ARM64")) then | |
sys.arch = "arm64" | |
elseif (string.match(os.getenv("PROCESSOR_ARCHITECTURE"), "AMD64")) then | |
sys.arch = "x86_64" | |
elseif (string.match(os.getenv("PROCESSOR_ARCHITECTURE"), "IA64")) then | |
sys.arch = "ia64" | |
elseif (string.match(os.getenv("PROCESSOR_ARCHITECTURE"), "EM64T")) then | |
sys.arch = "em64t" | |
end | |
else | |
local sysf = io.popen("uname -m") | |
local arch = sysf:read("*a") | |
if (string.match(arch, "arm32")) then | |
sys.arch = "arm32" | |
elseif (string.match(arch, "i*86")) then | |
sys.arch = "x86" | |
elseif (string.match(arch, "aarch64")) then | |
sys.arch = "aarch64" | |
elseif (string.match(arch, "aarch32") or string.match(arch, "aarch")) then | |
sys.arch = "aarch32" | |
elseif (string.match(arch, "arm64")) then | |
sys.arch = "arm64" | |
elseif (string.match(arch, "x86_64")) then | |
sys.arch = "x86_64" | |
end | |
sysf:close() | |
end | |
return sys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment