Skip to content

Commit

Permalink
ci: initial workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
luau-project committed Nov 9, 2024
1 parent 487bdca commit 7bd41c8
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 3 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: CI

on:
push:
paths-ignore:
- "**.md"
- "docs/**"
pull_request:
paths-ignore:
- "**.md"
- "docs/**"

jobs:
build:
name: Build
runs-on: ${{ matrix.os }}

defaults:
run:
shell: pwsh

strategy:
matrix:

lua-version:
- 5.1
- 5.2
- 5.3
- 5.4
- luajit-master

os:
- windows-latest
- ubuntu-latest

steps:

- name: Checkout
uses: actions/checkout@v4
with:
path: lua-uuid

- name: Install libuuid-dev
if: ${{ matrix.os == 'ubuntu-latest' }}
run: sudo apt install -y uuid-dev

- name: Setup MSVC dev-prompt
if: ${{ matrix.os == 'windows-latest' && matrix.lua-version != 'luajit-master' }}
uses: ilammy/msvc-dev-cmd@v1

- name: Setup Lua
uses: luarocks/gh-actions-lua@v10
with:
luaVersion: ${{ matrix.lua-version }}

- name: Setup LuaRocks
uses: luarocks/gh-actions-luarocks@v5

- name: Build lua-uuid
working-directory: lua-uuid
run: |
$rockspec = Get-ChildItem . -Recurse -File |
Where-Object Name -EQ "lua-uuid-dev-1.rockspec" |
Select-Object -ExpandProperty FullName -First 1;
$color = (0x1b -as [char]) + "[36m";
Write-Host "Building rockspec file: ${color}${rockspec}";
luarocks make $rockspec;
- name: Run samples
working-directory: lua-uuid
run: |
Get-ChildItem "samples" -Recurse -File |
Where-Object Extension -EQ ".lua" |
Select-Object -ExpandProperty FullName |
Foreach-Object {
$color = (0x1b -as [char]) + "[36m";
Write-Host "Running sample file: ${color}$_";
lua "$_";
};
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# lua-uuid

[![CI](https://github.com/luau-project/lua-uuid/actions/workflows/ci.yml/badge.svg)](./.github/workflows/ci.yml)

## Overview

**lua-uuid** is a lightweight, native library for Lua (5.1 and newer) to deal with Universally Unique Id (UUID).
Expand Down Expand Up @@ -34,7 +36,7 @@ On Linux, ```lua-uuid``` depends on ```libuuid```:
* On Debian-based distributions:

```bash
sudo apt install -y libuuid-dev
sudo apt install -y uuid-dev
```

* On RedHat-based distributions:
Expand Down
33 changes: 31 additions & 2 deletions src/lua-uuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,35 @@ static LuaUuid *lua_uuid_check(lua_State *L, int index)
return (LuaUuid *)ud;
}

// The following function
// was copied from Lua 5.4
// source code in order
// to provide compatibility
// to Lua 5.1 and Lua 5.2
static void *lua_uuid_testudata(lua_State *L, int ud, const char *tname)
{
#if LUA_VERSION_NUM == 501 || LUA_VERSION_NUM == 502
void *p = lua_touserdata(L, ud);
if (p != NULL)
{
if (lua_getmetatable(L, ud))
{
luaL_getmetatable(L, tname);
if (!lua_rawequal(L, -1, -2))
{
p = NULL;
}

lua_pop(L, 2);
return p;
}
}
return NULL;
#else
return luaL_testudata(L, ud, tname);
#endif
}

static int lua_uuid_new(lua_State *L)
{
int res = 1;
Expand Down Expand Up @@ -153,8 +182,8 @@ static int lua_uuid_equal(lua_State *L)
}
else
{
void *ud_left = luaL_testudata(L, 1, LUA_UUID_METATABLE);
void *ud_right = luaL_testudata(L, 2, LUA_UUID_METATABLE);
void *ud_left = lua_uuid_testudata(L, 1, LUA_UUID_METATABLE);
void *ud_right = lua_uuid_testudata(L, 2, LUA_UUID_METATABLE);

if (ud_left != NULL && ud_right != NULL)
{
Expand Down

0 comments on commit 7bd41c8

Please sign in to comment.