Created
March 29, 2013 15:15
-
-
Save westhood/5271465 to your computer and use it in GitHub Desktop.
Generate uuid via luajit ffi
This file contains hidden or 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
| 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