Skip to content

Instantly share code, notes, and snippets.

@anders
Created March 7, 2013 02:10
Show Gist options
  • Save anders/5105026 to your computer and use it in GitHub Desktop.
Save anders/5105026 to your computer and use it in GitHub Desktop.
#!/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