Skip to content

Instantly share code, notes, and snippets.

@westhood
Created March 29, 2013 15:15
Show Gist options
  • Select an option

  • Save westhood/5271465 to your computer and use it in GitHub Desktop.

Select an option

Save westhood/5271465 to your computer and use it in GitHub Desktop.
Generate uuid via luajit ffi
local ffi = require("ffi")
ffi.cdef[[
typedef unsigned char uuid_t[16];
void uuid_generate(uuid_t out);
void uuid_unparse(const uuid_t uu, char *out);
]]
local libuuid = ffi.os == "OSX" and ffi.C or ffi.load("uuid")
function uuid()
local buf = ffi.new('uint8_t[16]')
local uu = ffi.new('uint8_t[?]', 36)
libuuid.uuid_generate(buf)
libuuid.uuid_unparse(buf, uu)
return ffi.string(uu, 36)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment