Skip to content

Commit

Permalink
utils: add getOS()
Browse files Browse the repository at this point in the history
  • Loading branch information
emmericp committed Sep 19, 2015
1 parent e5cfcb8 commit 8582e0b
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lua/include/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,30 @@ end })
function unpackAll(tbl)
return unpackers[table.maxn(tbl)](tbl)
end

function run(cmd)
local file = io.popen(cmd, "r")
if not file then
return false
end
local s = assert(file:read('*a'))
file:close()
return s
end

--- Get the operation system type and version
-- @return osName, major, minor, patch
function getOS()
local os = run("uname")
if not os then
return nil
end
local ver = run("uname -r")
if not ver then
return os, 0, 0, 0
end
local major, minor, patch = tonumberall(ver:match("(%d+)%.(%d+)%.(%d+)"))
return trim(os), major, minor, patch
end


0 comments on commit 8582e0b

Please sign in to comment.