aboutsummaryrefslogtreecommitdiff
path: root/lua_uuid.c
diff options
context:
space:
mode:
authorThibault Charbonnier <thibaultcha@me.com>2015-11-07 01:53:33 -0800
committerThibault Charbonnier <thibaultcha@me.com>2015-11-07 02:02:03 -0800
commit03617b9a8cede011d5dbd7009bf7dab00ba67806 (patch)
treef2fbc2aab8f30bffdf8e2c3b6012de443e3d0274 /lua_uuid.c
parentb1696f33dd7ae2b621ad8d04f1547df57731d6d0 (diff)
downloadlua_uuid-03617b9a8cede011d5dbd7009bf7dab00ba67806.tar.gz
lua_uuid-03617b9a8cede011d5dbd7009bf7dab00ba67806.tar.bz2
lua_uuid-03617b9a8cede011d5dbd7009bf7dab00ba67806.zip
feat: made the module return a function
- also add lua lib path to the .so creation to ensure compilation (generally lua header files are not in the standrard compiler's search paths) - remove boilerplate - bare minimum of tests additions
Diffstat (limited to 'lua_uuid.c')
-rw-r--r--lua_uuid.c28
1 files changed, 7 insertions, 21 deletions
diff --git a/lua_uuid.c b/lua_uuid.c
index e0eca64..94d76b1 100644
--- a/lua_uuid.c
+++ b/lua_uuid.c
@@ -1,42 +1,28 @@
/***
-Utility for generating UUIDs
+Utility for generating UUIDs by wrapping libuuid's generate().
@license MIT
@module lua_uuid
*/
-#define LUA_LIB
#include <lua.h>
#include <lauxlib.h>
#include <uuid/uuid.h>
-#if LUA_VERSION_NUM < 502
-# define luaL_newlib(L,l) (lua_newtable(L), luaL_register(L,NULL,l))
-# define lua_rawlen lua_objlen
-#endif
-
-/// Generate an UUID
+/// Generate a UUID
// @return uuid_str
// @function generate()
static int generate(lua_State *L) {
-
- // Generate UUID
uuid_t uuid;
- uuid_generate(uuid);
+ char uuid_str[37];
- // Unparse to a string
- char uuid_str[37]; // For example: "1b4e28ba-2fa1-11d2-883f-0016d3cca427" + "\0"
+ uuid_generate(uuid);
uuid_unparse_lower(uuid, uuid_str);
lua_pushstring(L, uuid_str);
return 1;
}
-static const luaL_Reg lua_uuid[] = {
- {"generate", generate},
- {NULL, NULL}
-};
-
-int luaopen_lua_uuid(lua_State *L){
- luaL_newlib(L, lua_uuid);
+int luaopen_lua_uuid(lua_State *L) {
+ lua_pushcfunction(L, generate);
return 1;
-} \ No newline at end of file
+}