Created
March 7, 2013 02:10
-
-
Save anders/5105026 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env luajit | |
-- Original source code at: | |
-- http://www.opensource.apple.com/source/DarwinTools/DarwinTools-1/sw_vers.c | |
local ffi = require 'ffi' | |
local CF = require 'CoreFoundation' | |
ffi.cdef[[ | |
CFDictionaryRef _CFCopyServerVersionDictionary(void); | |
CFDictionaryRef _CFCopySystemVersionDictionary(void); | |
const CFStringRef _kCFSystemVersionProductNameKey; | |
const CFStringRef _kCFSystemVersionProductVersionKey; | |
const CFStringRef _kCFSystemVersionBuildVersionKey; | |
]] | |
local dict = CF._CFCopyServerVersionDictionary() | |
if dict == nil then | |
dict = CF._CFCopySystemVersionDictionary() | |
end | |
if dict == nil then | |
return 1 | |
end | |
ffi.gc(dict, CF.CFRelease) | |
print('ProductName:', dict[CF._kCFSystemVersionProductNameKey]) | |
print('ProductVersion:', dict[CF._kCFSystemVersionProductVersionKey]) | |
print('BuildVersion:', dict[CF._kCFSystemVersionBuildVersionKey]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment