Skip to content

Commit 75d6287

Browse files
committedNov 15, 2024·
feature: Added support for FreeBSD, NetBSD, OpenBSD and DragonFly.
1 parent 7ca2733 commit 75d6287

File tree

5 files changed

+143
-24
lines changed

5 files changed

+143
-24
lines changed
 

‎.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
- "docs/**"
1212

1313
env:
14-
ROCKSPEC_VERSION: 0.0.3
14+
ROCKSPEC_VERSION: 0.0.4
1515
DEV_ROCKSPEC: lua-uuid-dev-1.rockspec
1616

1717
jobs:

‎README.md

+16-7
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
**lua-uuid** is a lightweight, native library for Lua (5.1 and newer) to deal with Universally Unique Id (UUID).
88

9-
* On Linux, it uses ```libuuid``` to generate UUIDs;
9+
* On Linux and BSD, it uses ```libuuid``` to generate UUIDs;
1010
* On Windows, it uses the WINAPI ```rpcrt4``` library;
11-
* On MacOS / iOS, it uses the ```CoreFoundation``` framework.
11+
* On macOS / iOS, it uses the ```CoreFoundation``` framework.
1212

1313
## Table of Contents
1414

@@ -33,19 +33,25 @@
3333

3434
> [!IMPORTANT]
3535
>
36-
> On Linux, ```lua-uuid``` depends on ```libuuid```:
36+
> On Linux and BSD, ```lua-uuid``` depends on ```libuuid```:
3737
>
38-
> * On Debian-based distributions:
38+
> * On Debian-based (e.g: Ubuntu) distributions:
3939
>
4040
> ```bash
4141
> sudo apt install -y uuid-dev
4242
> ```
4343
>
44-
> * On RedHat-based distributions:
44+
> * On RedHat-based (e.g: Fedora) distributions:
4545
>
4646
> ```bash
4747
> sudo dnf install libuuid-devel
4848
> ```
49+
>
50+
> * On BSD-based (e.g: FreeBSD) distributions:
51+
>
52+
> ```bash
53+
> pkg install e2fsprogs-libuuid
54+
> ```
4955
5056
Assuming that [LuaRocks](https://luarocks.org/) is properly installed and configured on your system, execute the following command:
5157

@@ -165,7 +171,7 @@ print(id3:isnil())
165171

166172
### parse
167173

168-
* *Description*: Generates a new GUID / UUID from a string value
174+
* *Description*: Parses a GUID / UUID from a string value
169175
* *Signature*: ```parse(value)```
170176
* *value* (string): the string to be parsed
171177
* *return*: ```(userdata)```
@@ -207,8 +213,11 @@ print(id3:isnil())
207213

208214
## Change log
209215

216+
* v0.0.4:
217+
* Added support for BSD (e.g: FreeBSD, NetBSD, OpenBSD and DragonFly);
218+
* Moved ```#include <lua.h>``` and ```LUA_UUID_EXPORT``` macro definition to outside of ```__cplusplus``` declarations on ```lua-uuid.h```.
210219
* v0.0.3:
211-
* Changed to throw issue when ```lua_newuserdata``` returns ```NULL```;
220+
* Changed to throw error when ```lua_newuserdata``` returns ```NULL```;
212221
* Added macro ```LUA_UUID_BUILD_SHARED``` to ```CFLAGS_EXTRA``` on macos;
213222
* Changed ```luajit-master``` to ```luajit``` on CI when testing for ```LuaJIT```;
214223
* Added print statements on [tostring.lua](./samples/tostring.lua) sample;

‎rockspecs/lua-uuid-0.0.4-0.rockspec

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package = "lua-uuid"
2+
version = "0.0.4-0"
3+
4+
source = {
5+
url = "git://github.com/luau-project/lua-uuid.git",
6+
tag = "v0.0.4"
7+
}
8+
9+
description = {
10+
homepage = "https://github.com/luau-project/lua-uuid",
11+
summary = [[Lightweight, native GUID / UUID library for Lua]],
12+
detailed = [=[
13+
lua-uuid is a lightweight, native library for Lua (5.1 and newer) to deal with Universally Unique Id (UUID).
14+
15+
* On Linux and BSD, it uses libuuid to generate UUIDs;
16+
* On Windows, it uses the WINAPI rpcrt4 library;
17+
* On macOS / iOS, it uses the CoreFoundation framework.
18+
19+
Visit the GitHub repository for more information.]=],
20+
license = "MIT"
21+
}
22+
23+
supported_platforms = { "linux", "windows", "cygwin", "macosx", "bsd" }
24+
25+
dependencies = {
26+
"lua >= 5.1"
27+
}
28+
29+
external_dependencies = {
30+
platforms = {
31+
linux = {
32+
["UUID"] = {
33+
header = "uuid/uuid.h"
34+
}
35+
},
36+
bsd = {
37+
["UUID"] = {
38+
header = "uuid/uuid.h"
39+
}
40+
}
41+
}
42+
}
43+
44+
local function build_plat(plat)
45+
if (plat == "linux" or plat == "bsd") then
46+
return {
47+
type = "builtin",
48+
modules = {
49+
["lua-uuid"] = {
50+
sources = { "src/lua-uuid.c" },
51+
libraries = { "uuid" },
52+
defines = { "LUA_UUID_BUILD_SHARED", "LUA_UUID_USE_LIBUUID" },
53+
incdirs = { "src", "$(UUID_INCDIR)" },
54+
libdirs = { "$(UUID_LIBDIR)" }
55+
}
56+
}
57+
}
58+
elseif (plat == "windows" or plat == "cygwin") then
59+
return {
60+
type = "builtin",
61+
modules = {
62+
["lua-uuid"] = {
63+
sources = { "src/lua-uuid.c" },
64+
libraries = { "rpcrt4" },
65+
defines = { "LUA_UUID_BUILD_SHARED", "LUA_UUID_USE_WIN32" },
66+
incdirs = { "src" },
67+
libdirs = { }
68+
}
69+
}
70+
}
71+
elseif (plat == "macosx") then
72+
return {
73+
type = "make",
74+
makefile = "Makefile.macosx",
75+
build_variables = {
76+
CFLAGS = "$(CFLAGS)",
77+
LIBFLAG = "$(LIBFLAG)",
78+
CFLAGS_EXTRA = "-DLUA_UUID_BUILD_SHARED -DLUA_UUID_USE_APPLE",
79+
LIBFLAG_EXTRA = "-framework CoreFoundation",
80+
LUA_INCDIR = "$(LUA_INCDIR)",
81+
LUA_LIBDIR = "$(LUA_INCDIR)/../lib",
82+
OBJ_EXTENSION = "$(OBJ_EXTENSION)",
83+
LIB_EXTENSION = "$(LIB_EXTENSION)"
84+
},
85+
install_variables = {
86+
INSTALL_PREFIX = "$(PREFIX)",
87+
INSTALL_LIBDIR = "$(LIBDIR)",
88+
LUA_VERSION = "$(LUA_VERSION)",
89+
LIB_EXTENSION = "$(LIB_EXTENSION)"
90+
}
91+
}
92+
else
93+
error("Unknown platform", 2)
94+
end
95+
end
96+
97+
build = {
98+
platforms = {
99+
linux = build_plat("linux"),
100+
windows = build_plat("windows"),
101+
cygwin = build_plat("cygwin"),
102+
macosx = build_plat("macosx"),
103+
bsd = build_plat("bsd")
104+
}
105+
}

‎rockspecs/lua-uuid-dev-1.rockspec

+17-12
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ description = {
1111
detailed = [=[
1212
lua-uuid is a lightweight, native library for Lua (5.1 and newer) to deal with Universally Unique Id (UUID).
1313
14-
* On Linux, it uses libuuid to generate UUIDs;
14+
* On Linux and BSD, it uses libuuid to generate UUIDs;
1515
* On Windows, it uses the WINAPI rpcrt4 library;
16-
* On MacOS / iOS, it uses the CoreFoundation framework.
16+
* On macOS / iOS, it uses the CoreFoundation framework.
1717
1818
Visit the GitHub repository for more information.]=],
1919
license = "MIT"
2020
}
2121

22-
supported_platforms = { "linux", "win32", "mingw", "cygwin", "macosx" }
22+
supported_platforms = { "linux", "windows", "cygwin", "macosx", "bsd" }
2323

2424
dependencies = {
2525
"lua >= 5.1"
@@ -31,12 +31,17 @@ external_dependencies = {
3131
["UUID"] = {
3232
header = "uuid/uuid.h"
3333
}
34+
},
35+
bsd = {
36+
["UUID"] = {
37+
header = "uuid/uuid.h"
38+
}
3439
}
3540
}
3641
}
3742

38-
local function make_plat(plat)
39-
if (plat == "linux") then
43+
local function build_plat(plat)
44+
if (plat == "linux" or plat == "bsd") then
4045
return {
4146
type = "builtin",
4247
modules = {
@@ -49,7 +54,7 @@ local function make_plat(plat)
4954
}
5055
}
5156
}
52-
elseif (plat == "win32" or plat == "mingw" or plat == "cygwin") then
57+
elseif (plat == "windows" or plat == "cygwin") then
5358
return {
5459
type = "builtin",
5560
modules = {
@@ -58,7 +63,7 @@ local function make_plat(plat)
5863
libraries = { "rpcrt4" },
5964
defines = { "LUA_UUID_BUILD_SHARED", "LUA_UUID_USE_WIN32" },
6065
incdirs = { "src" },
61-
libdirs = {}
66+
libdirs = { }
6267
}
6368
}
6469
}
@@ -90,10 +95,10 @@ end
9095

9196
build = {
9297
platforms = {
93-
linux = make_plat("linux"),
94-
win32 = make_plat("win32"),
95-
mingw = make_plat("mingw"),
96-
cygwin = make_plat("cygwin"),
97-
macosx = make_plat("macosx")
98+
linux = build_plat("linux"),
99+
windows = build_plat("windows"),
100+
cygwin = build_plat("cygwin"),
101+
macosx = build_plat("macosx"),
102+
bsd = build_plat("bsd")
98103
}
99104
}

‎src/lua-uuid.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#ifndef LUA_UUID_H
22
#define LUA_UUID_H
33

4-
#ifdef __cplusplus
5-
extern "C" {
6-
#endif
4+
#include <lua.h>
75

86
#ifdef LUA_UUID_BUILD_STATIC
97
#define LUA_UUID_EXPORT
@@ -31,7 +29,9 @@ extern "C" {
3129
#endif
3230
#endif
3331

34-
#include <lua.h>
32+
#ifdef __cplusplus
33+
extern "C" {
34+
#endif
3535

3636
LUA_UUID_EXPORT
3737
int luaopen_uuid(lua_State *L);

0 commit comments

Comments
 (0)
Please sign in to comment.