Skip to content

Commit 25f1425

Browse files
authored
feat: add lua 5.4.7 (C library) (#4)
* feat: add lua 5.4.7 (C library) Pure-C scripting library; relies on mcpp's C compile rule. Form B descriptor enumerates the 32 library translation units (CORE_O + LIB_O from upstream's src/Makefile) into a single `liblua.a` static archive. The two binary entry points (src/lua.c interpreter, src/luac.c bytecode compiler) are intentionally excluded — both define `int main()` and aren't part of the embeddable library. Tarball: https://www.lua.org/ftp/lua-5.4.7.tar.gz SHA256: 9fbf5e28ef86c69858f6d3d34eccc32e911c1a28b4120ff3e84aaa70cfbf1e30 Verified end-to-end with a small consumer that calls lua_State / luaL_openlibs / luaL_dostring("return 1+2") — outputs "3", links clean against liblua.a, no main() collision. * fix(ci): rewrite the package-descriptor lint The previous check insisted on `schema = "0.1"` and an inline `mcpp = { ... }` segment. Both are wrong for the actual xpkg V1 schema we use: - xpkg V1 names the version field `spec`, not `schema`. (None of the existing descriptors in this repo carry `schema = "0.1"`, so this check would have flagged every file the moment any pkgs/ change triggered the workflow.) - The inline `mcpp = {}` segment is Form B only; Form A descriptors (mcpplibs.tinyhttps, mcpplibs.llmapi after their upstream started shipping mcpp.toml) intentionally omit it. Replace both with the actual xpkg V1 baseline: - `package = { ... }` assignment present (via syntax-only `loadfile` parse — catches typos without executing user code) - required fields: `spec`, `name`, `xpm` - still flag the forbidden `function install(...)` hook Adds a `lua5.4` install step so the syntax check has an interpreter.
1 parent 160c504 commit 25f1425

2 files changed

Lines changed: 104 additions & 7 deletions

File tree

.github/workflows/validate.yml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: validate
22

33
on:
44
pull_request:
5-
paths: ["pkgs/**/*.lua"]
5+
paths: ["pkgs/**/*.lua", ".github/workflows/validate.yml"]
66
push:
77
branches: [main]
88

@@ -11,22 +11,33 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v4
14+
- name: Install lua
15+
run: sudo apt-get install -y --no-install-recommends lua5.4
1416
- name: Lint package descriptors
1517
run: |
1618
fail=0
1719
for f in pkgs/*/*.lua; do
20+
# 1. Forbidden install hook (security: descriptors must not run code)
1821
if grep -q "^function install" "$f"; then
1922
echo "::error file=$f::install hook is forbidden"
2023
fail=1
2124
fi
22-
if ! grep -q "mcpp = {" "$f"; then
23-
echo "::error file=$f::missing mcpp = {} segment"
24-
fail=1
25-
fi
26-
if ! grep -q 'schema *= *"0\.1"' "$f"; then
27-
echo "::error file=$f::missing schema = \"0.1\""
25+
# 2. Lua syntax check — load (= compile) without executing.
26+
# `loadfile(name, 't')` rejects bytecode and parses text only.
27+
if ! lua5.4 -e "assert(loadfile('$f', 't'))" >/dev/null 2>&1; then
28+
echo "::error file=$f::lua syntax error"
2829
fail=1
2930
fi
31+
# 3. xpkg V1 baseline: the file has to populate `package = { ... }`
32+
# with at least `spec`, `name`, and an `xpm` table. Form A vs
33+
# Form B (mcpp = "<path>" / mcpp = { ... }) is descriptor-author
34+
# choice and not enforced here.
35+
for needle in 'spec *=' 'name *=' 'xpm *='; do
36+
if ! grep -q "$needle" "$f"; then
37+
echo "::error file=$f::missing required field ($needle)"
38+
fail=1
39+
fi
40+
done
3041
done
3142
[ $fail -eq 0 ] && echo "All package files valid."
3243
exit $fail

pkgs/l/lua.lua

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
-- M6.x glob-aware Form B descriptor for Lua 5.4.
2+
--
3+
-- Pure-C library; relies on mcpp 0.0.2's C-language compile rule (`.c`
4+
-- routed to `c_object` via the gcc/clang sibling driver). Builds the
5+
-- 32 library translation units (CORE_O + LIB_O from upstream's
6+
-- src/Makefile) into a single static archive `liblua.a`. The two
7+
-- binary entry points (`src/lua.c` for the interpreter and
8+
-- `src/luac.c` for the bytecode compiler) are intentionally excluded —
9+
-- both define `int main()` and aren't part of the embeddable library.
10+
-- Consumers `#include <lua.h>` and link against liblua.a.
11+
12+
package = {
13+
spec = "1",
14+
name = "lua",
15+
description = "A powerful, efficient, lightweight, embeddable scripting language",
16+
licenses = {"MIT"},
17+
repo = "https://www.lua.org",
18+
type = "package",
19+
20+
xpm = {
21+
linux = {
22+
["5.4.7"] = {
23+
url = "https://www.lua.org/ftp/lua-5.4.7.tar.gz",
24+
sha256 = "9fbf5e28ef86c69858f6d3d34eccc32e911c1a28b4120ff3e84aaa70cfbf1e30",
25+
},
26+
},
27+
macosx = {
28+
["5.4.7"] = {
29+
url = "https://www.lua.org/ftp/lua-5.4.7.tar.gz",
30+
sha256 = "9fbf5e28ef86c69858f6d3d34eccc32e911c1a28b4120ff3e84aaa70cfbf1e30",
31+
},
32+
},
33+
windows = {
34+
["5.4.7"] = {
35+
url = "https://www.lua.org/ftp/lua-5.4.7.tar.gz",
36+
sha256 = "9fbf5e28ef86c69858f6d3d34eccc32e911c1a28b4120ff3e84aaa70cfbf1e30",
37+
},
38+
},
39+
},
40+
41+
-- Form B `mcpp` segment: paths are globs relative to the verdir
42+
-- (~/.mcpp/registry/data/xpkgs/<idx>-x-lua/<ver>/). The leading
43+
-- `*/` absorbs the upstream tarball's `lua-5.4.7/` wrap layer.
44+
mcpp = {
45+
language = "c++23", -- top-level [package].standard knob; mcpp drives a c++23 toolchain even for pure-C deps.
46+
import_std = false, -- pure C — no `import std;`.
47+
c_standard = "c99", -- Lua's reference build is c99-clean; matches upstream src/Makefile.
48+
include_dirs = { "*/src" }, -- public headers (lua.h, lualib.h, lauxlib.h, luaconf.h) live next to .c files.
49+
sources = {
50+
"*/src/lapi.c",
51+
"*/src/lauxlib.c",
52+
"*/src/lbaselib.c",
53+
"*/src/lcode.c",
54+
"*/src/lcorolib.c",
55+
"*/src/lctype.c",
56+
"*/src/ldblib.c",
57+
"*/src/ldebug.c",
58+
"*/src/ldo.c",
59+
"*/src/ldump.c",
60+
"*/src/lfunc.c",
61+
"*/src/lgc.c",
62+
"*/src/linit.c",
63+
"*/src/liolib.c",
64+
"*/src/llex.c",
65+
"*/src/lmathlib.c",
66+
"*/src/lmem.c",
67+
"*/src/loadlib.c",
68+
"*/src/lobject.c",
69+
"*/src/lopcodes.c",
70+
"*/src/loslib.c",
71+
"*/src/lparser.c",
72+
"*/src/lstate.c",
73+
"*/src/lstring.c",
74+
"*/src/lstrlib.c",
75+
"*/src/ltable.c",
76+
"*/src/ltablib.c",
77+
"*/src/ltm.c",
78+
"*/src/lundump.c",
79+
"*/src/lutf8lib.c",
80+
"*/src/lvm.c",
81+
"*/src/lzio.c",
82+
},
83+
targets = { ["lua"] = { kind = "lib" } },
84+
deps = { },
85+
},
86+
}

0 commit comments

Comments
 (0)