aboutsummaryrefslogtreecommitdiff
path: root/lua_uuid.c
blob: 94d76b1e3da22a98b339991f5abce42d82fd6639 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/***
Utility for generating UUIDs by wrapping libuuid's generate().

@license MIT
@module lua_uuid
*/
#include <lua.h>
#include <lauxlib.h>
#include <uuid/uuid.h>

/// Generate a UUID
// @return uuid_str
// @function generate()
static int generate(lua_State *L) {
    uuid_t uuid;
    char uuid_str[37];

    uuid_generate(uuid);
    uuid_unparse_lower(uuid, uuid_str);

    lua_pushstring(L, uuid_str);
    return 1;
}

int luaopen_lua_uuid(lua_State *L) {
    lua_pushcfunction(L, generate);
    return 1;
}