ws-polish: README / STYLE module lists and format counts from the tree, checked by a DOCS lint rule

tools/lint_rules.py DOCS: the README and STYLE layout blocks must name every codecs/<domain>/<Name>,
containers/ and core/ module; README's format counts must match docs/FORMATS.md; the guide index must
link every guide page. STYLE's 'use what exists' table lists the wave-3 shared modules.
This commit is contained in:
4DBug committed 2026-10-31 17:16:08 -05:00
1 parent 42e96a0964
commit 84fb8f42f1
4 files changed
+132 -37

No files matched your search

+39 -28
View File
@@ -5,10 +5,11 @@ generation) and on **LuaJIT / LÖVE** (through `tools/build.py`). Every format o
(`src/Formats/Types.luau`): a PNG and a WebP both load as an `Image`, every audio format opens as the same streaming
`Decoder`, every model format loads as a `Scene`.
About 76 formats across images, audio, video, 3D models, CAD, fonts, archives, data, vector graphics, layered images,
subtitles, music and playlists: see [docs/FORMATS.md](docs/FORMATS.md) (generated from the code) for the list and each
format's capabilities, [docs/API.md](docs/API.md) for the whole API, and the guide
([docs/guide/README.md](docs/guide/README.md)) for walkthroughs.
174 formats: images (25), audio (21), video (11), 3D models (32), CAD (1), fonts (11), archives (31), data (11),
vector graphics and tile maps (2), layered images (3), subtitles (3), music (20) and playlists (3). See
[docs/FORMATS.md](docs/FORMATS.md) (generated from the code) for the list and each format's capabilities,
[docs/API.md](docs/API.md) for the whole API, and the guide ([docs/guide/README.md](docs/guide/README.md)) for
walkthroughs. `tools/lint.sh` checks these counts against the registry.
```luau
local F = require(Formats) -- LuaJIT: require("formats"); luau CLI: require("@formats")
@@ -41,33 +42,38 @@ standard library pieces come from `formats/_compat.lua`). Copy the `formats` fol
## Quick start
```luau
-- images: PNG / APNG, JPEG, WebP, GIF, BMP, TGA, QOI, TIFF, ICO, PNM, HDR -> Image (rgba8 pixels in a buffer)
-- images: PNG / APNG, JPEG, WebP, GIF, BMP, TGA, QOI, TIFF, ICO, PNM, HDR, EXR, DDS, KTX, PCX, ... -> Image
local img = F.image.load(pngBytes)
print(img.width, img.height, #(img.frames or {}), img.loops) -- animations: frames; loops = play count, 0 forever
local jpg = F.save(img, nil, { format = "jpeg", quality = 85 })
-- audio: WAV, FLAC, MP3 / MP2, Ogg Vorbis, Opus, AAC, M4A, AIFF, AU, CAF, VOC -> streaming Decoder or Audio
-- audio: WAV, FLAC, MP3 / MP2, Ogg Vorbis, Opus, AAC, M4A, AIFF, AU, CAF, VOC, WavPack, APE, TTA, Musepack, AC-3,
-- QOA, ADPCM (ADX, VAG, BRSTM, ...) -> streaming Decoder or Audio
local dec = F.audio.open(flacBytes) -- dec:read(n) -> interleaved f32 buffer, frames; dec:seek(s)
local song = F.audio.load(mp3Bytes) -- Audio { sampleRate, channels, frames, samples, tags }
local mono = F.ops.audio.downmix(song, 1) -- channels are in WAVE order; tags keys are lower case
local opus = F.save(F.ops.audio.resample(mono, 48000), nil, { format = "opus", bitrate = 64000 })
-- video: MP4 / MOV, MKV / WebM, AVI, MPEG-TS / PS, Y4M (+ animated images) -> VideoDecoder
-- video: MP4 / MOV, MKV / WebM, AVI, MPEG-TS / PS, Ogg Theora, FLV, FLI, Smacker, Y4M (+ animated images)
-- -> VideoDecoder
local v = F.video.open(mp4Bytes) -- v:nextFrame() -> frame (image yuv420p or rgba8, pts)
-- models: glTF / GLB (+ Draco), OBJ, STL, PLY, FBX, Collada, 3MF, USDA, OFF, VOX, 3DS, MS3D, LWO, .x, IQM, B3D,
-- PMX / PMD, VRML, X3D, LDraw -> Scene
-- PMX / PMD, VRML, X3D, LDraw, MD2 / MD3 / MDL / MD5, BSP, SMD, Roblox (rbxm / rbxmx / .mesh),
-- Minecraft (.schem, .mca), Qubicle -> Scene
local scene = F.model.load(glbBytes)
local prim = F.ops.mesh.merge(scene) -- one triangle primitive in world space
-- fonts, archives, data, vector, layered, subtitles, music, playlists
local font = F.font.load(ttfBytes) -- outlines, metrics, kerning
local zip = F.archive.load(zipBytes) -- entries; F.archive.save writes zip / tar / gzip
local t = F.data.load('{"a": [1, 2]}', { format = "json" }) -- JSON, XML, YAML, TOML, CSV, INI, plist, msgpack, CBOR
local icon = F.ops.vector.rasterize(F.vector.load(svgText), 64, 64)
local flat = F.ops.layers.flatten(F.layered.load(psdBytes))
local subs = F.subtitle.load(srtText)
local tune = F.music.load(modBytes) -- MOD / S3M / XM / IT / MIDI, rendered to audio on request
-- CAD, fonts, archives, data, vector, tile maps, layered, subtitles, music, playlists
local font = F.font.load(ttfBytes) -- TTF / OTF, WOFF / WOFF2, BMFont, bitmap fonts: outlines, kerning
local zip = F.archive.load(zipBytes) -- zip, tar, 7z, gzip, cab, iso, ...; saves zip / tar / gzip
local t = F.data.load('{"a": [1, 2]}', { format = "json" }) -- JSON, XML, YAML, TOML, CSV, INI, plist, CBOR, NBT, ...
local icon = F.ops.vector.rasterize(F.vector.load(svgText), 64, 64) -- SVG; Tiled maps load as a TileMap
local flat = F.ops.layers.flatten(F.layered.load(psdBytes)) -- PSD, Aseprite, OpenRaster
local subs = F.subtitle.load(srtText) -- SRT, WebVTT, ASS / SSA
local tune = F.music.load(modBytes) -- MOD / S3M / XM / IT / AHX / MIDI, ...: rendered to audio
local step = F.cad.load(stepText) -- STEP entity graph (B-rep through a plug-in)
local list = F.playlist.load(m3uText) -- M3U / M3U8, PLS, XSPF
```
## The API in short
@@ -100,20 +106,25 @@ hands to formats (decodeImage / encodeImage / openAudio / plugins): [docs/API.md
```
src/Formats/
init.luau Registry.luau (generated) api: F.*
ops/ editing on the standard types (ImageOps, MeshOps, LayerOps, AudioOps)
ops/ editing on the standard types (ImageOps, MeshOps, LayerOps, AudioOps, ...)
<category>/<fmt>/ formats: only what is specific to the format (parsing, mapping, writing)
containers/ Chunks, Riff, IsoBmff, Ebml, Ogg, Zip, Tar, Avi, MpegTs, MpegPs, ...
codecs/compress/ Deflate, Lzma, Zstd, Brotli, Bzip2, Lzw
codecs/entropy/ Huffman, RangeCoder
codecs/image/ Jpeg, Dct, Vp8, Vp8L, Pixels, Yuv, Quantize, Raster, Blend
codecs/audio/ Opus, Vorbis, Flac, Mpa (MP1-3), Aac, Alac, Mdct, Pcm, Stream, Resample,
VorbisComment, Tracker, SoundFont
codecs/video/ H264, Mpeg1, Video (the codec registry)
codecs/text/ codecs/font/ codecs/model/ Json, Xml, Text, Url / TrueType, Cff / Mat4, MeshFlatten, Draco,
Sampler, Vrml, Rig
containers/ Archive AudioWrap Avi Chunks Cpio Demux Ebml Fat Iso9660 IsoBmff MacFile
MpegEs MpegPs MpegTs Ogg Riff Tar Zip
codecs/compress/ Brotli Bzip2 Deflate Explode Lz4 Lzh Lzma Lzw Lzx PackBits Quantum
UnixCompress Xxh32 Zstd
codecs/entropy/ Huffman RangeCoder
codecs/image/ Bcn Blend Dct Etc Half Jpeg Pixels Quantize Raster Texel Texture Vp8 Vp8L Yuv
codecs/audio/ Aac Ac3 Adpcm Alac Ape ApeTag Flac Hively Mdct MidiRender Mpa (MP1-3)
Musepack Opus Pcm Qoa Resample SoundFont Stream Tracker Tta Vorbis
VorbisComment WavPack
codecs/video/ Dsp H263 H264 Legacy (FLI, Cinepak, MSV1, QT RLE, SMC, Smacker) Mpeg1 Mpeg2
Theora Video (the codec registry)
codecs/text/ Json Nbt Text Url Xml
codecs/font/ Bitmap Cff GlyphNames TrueType
codecs/model/ Draco Mat4 MeshFlatten Minecraft Polygon Rbx Rig Sampler Vrml
host/ runtime adapters (only the api uses them)
Types.luau the standard types + constructors
core/ Bytes, Bits, Err, Crc32, Adler32, Base64, Md5, Input, Sniff
core/ Adler32 Base64 Bits Bytes Crc16 Crc32 Err Input Md5 Sniff
compat/luajit.lua tools/ tests/ (T.luau, <category>/<fmt>.luau, codecs/, containers/, gen/) docs/ licenses/
examples/love/
```
@@ -125,7 +136,7 @@ How the layers fit, the format contract, and what belongs in a format folder: [d
```sh
bash tools/test.sh # fixtures, registry, build, every test under luau --codegen -O2 and LuaJIT, lint
bash tools/test.sh png # one test (both runtimes), no lint
bash tools/lint.sh # globals, type baseline, headers, requires, native-throw, layers, deps, contract, DUP
bash tools/lint.sh # globals, types, headers, requires, native-throw, layers, deps, contract, DUP, docs
bash tools/bench.sh # throughput on both runtimes (pin it: taskset -c 2 bash tools/bench.sh)
python3 -I tools/build.py # build/roblox + build/luajit
python3 -I tools/gen_registry.py # src/Formats/Registry.luau + docs/FORMATS.md from the format folders
+25 -8
View File
@@ -23,17 +23,23 @@ src/Formats/
mesh / layers / audio / music; ImageOps, ...)
<category>/<fmt>/ formats (layer 5) image audio video model cad font archive data
vector layered subtitle music playlist
containers/ containers (layer 4) Chunks, Riff, IsoBmff, Ebml, Ogg, Zip, Tar, ...
containers/ containers (layer 4) Archive AudioWrap Avi Chunks Cpio Demux Ebml
Fat Iso9660 IsoBmff MacFile MpegEs MpegPs
MpegTs Ogg Riff Tar Zip
codecs/<domain>/<Name> codecs (layer 3) generic algorithms, by domain:
compress/ Deflate Lzma Zstd Brotli Bzip2 Lzw Lz4 entropy/ Huffman RangeCoder
image/ Jpeg Dct Vp8 Vp8L Pixels Yuv Quantize Raster Blend
audio/ Opus Vorbis Flac Mpa Aac Alac Mdct Pcm Stream Resample VorbisComment Tracker SoundFont
video/ H264 Mpeg1 Video (the video codec registry) text/ Json Xml Text Url
font/ TrueType Cff model/ Mat4 MeshFlatten Rbx
compress/ Brotli Bzip2 Deflate Explode Lz4 Lzh Lzma Lzw Lzx PackBits Quantum UnixCompress Xxh32 Zstd
entropy/ Huffman RangeCoder
image/ Bcn Blend Dct Etc Half Jpeg Pixels Quantize Raster Texel Texture Vp8 Vp8L Yuv
audio/ Aac Ac3 Adpcm Alac Ape ApeTag Flac Hively Mdct MidiRender Mpa Musepack Opus Pcm Qoa Resample
SoundFont Stream Tracker Tta Vorbis VorbisComment WavPack
video/ Dsp H263 H264 Legacy Mpeg1 Mpeg2 Theora Video (the video codec registry)
text/ Json Nbt Text Url Xml
font/ Bitmap Cff GlyphNames TrueType
model/ Draco Mat4 MeshFlatten Minecraft Polygon Rbx Rig Sampler Vrml
host/ host (layer 2) runtime adapters; only the api uses them
Types.luau types (layer 1) standard types + constructors
core/ core (layer 0) Bytes, Bits, Err, Crc32, Adler32, Base64, Md5,
Input, Sniff (runtime-neutral primitives)
core/ core (layer 0) Adler32 Base64 Bits Bytes Crc16 Crc32 Err Input
Md5 Sniff (runtime-neutral primitives)
```
LAYERS: a module requires only what is below it. core requires core; Types requires core; codecs require core, Types
@@ -207,6 +213,17 @@ them. Anything generic goes down a layer and is called:
| sniffing text (BOM) / magic | `core/Sniff` |
| private-submodule errors -> Err | `core/Err.from` |
| UTF-8 code points, text decoding | `codecs/text/Text` |
| ADPCM (IMA, MS, ADX, PS-ADPCM, DSP, Flash, ModPlug) | `codecs/audio/Adpcm` |
| APE tags | `codecs/audio/ApeTag` |
| GPU texture pixels (BCn, ETC / EAC, uncompressed texel layouts, half floats) | `codecs/image/Texture` (`Bcn`, `Etc`, `Texel`, `Half`) |
| animation channels sampled at a time; game-model frames, joints and skins -> Scene | `codecs/model/Sampler`, `codecs/model/Rig` |
| polygons with holes -> triangles | `codecs/model/Polygon` |
| NBT / SNBT values; Minecraft block states and colours | `codecs/text/Nbt`, `codecs/model/Minecraft` |
| Roblox instance trees and property values | `codecs/model/Rbx` |
| bitmap fonts as a Font; PostScript glyph names | `codecs/font/Bitmap`, `codecs/font/GlyphNames` |
| CRC-16 (XMODEM / ARC), xxHash32 | `core/Crc16`, `codecs/compress/Xxh32` |
| Mac files (data + resource forks), FAT / ISO 9660 file systems, cpio | `containers/MacFile`, `containers/Fat`, `containers/Iso9660`, `containers/Cpio` |
| 8x8 IDCT and half-pel motion compensation of MPEG-style video | `codecs/video/Dsp` |
DUP enforces the direction: a function body of 12 or more code lines repeated token for token in another module
fails the lint. When two formats need the same code, move it down (to `codecs/<domain>/` or `containers/`) instead of
+1 -1
View File
@@ -5,7 +5,7 @@
# TYPES: the other type diagnostics are counted (unique lines: the analyzer reports a required module once per
# path spelling) and printed with LINT_TYPES=1. The count may not rise above tools/lint_types_baseline.txt; when
# it drops, lower the baseline (LINT_TYPES_UPDATE=1 writes the current count), so it only goes down.
# 2. HEADER, REQUIRE, NATIVE (native code never throws: it crashes Roblox Studio), LAYERS, DEPS, CONTRACT:
# 2. HEADER, REQUIRE, NATIVE (native code never throws: it crashes Roblox Studio), LAYERS, DEPS, CONTRACT, DUP, DOCS:
# tools/lint_rules.py (its header lists the rules; docs/STYLE.md explains them).
# 3. The generated registry / docs/FORMATS.md are up to date (tools/gen_registry.py --check), and tools/build.py's
# token passes pass their self-test.
+67
View File
@@ -20,6 +20,9 @@
# DUP no copy-pasted code: a function body of DUP_LINES (12) or more code lines whose tokens (comments and
# whitespace dropped, identifiers kept) equal another module's function body fails; move it down to a
# shared module (core / codecs / containers) and call it from both.
# DOCS the module lists in README.md's Layout block and docs/STYLE.md's layer block name every codec
# (codecs/<domain>/<Name>), container and core module in the tree; README.md's format counts
# ("images (25)", ...) match the registry (docs/FORMATS.md); docs/guide/README.md links every guide page.
import os, re, sys
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -314,5 +317,69 @@ for key, where in bodies.items():
if f != first[0]:
bad(f, ln, "DUP: `%s` repeats %s:%d (move it to a shared module)" % (head[:60], os.path.relpath(first[0], ROOT), first[1]))
# ---------------------------------------------------------------------------------------------------- DOCS
def module_names(rel):
"""the module names directly under src/Formats/<rel>: Foo.luau and Foo/ (a folder module)"""
d = os.path.join(SRC, rel)
names = set()
for n in os.listdir(d):
if n.endswith(".luau"):
names.add(n[:-5])
elif os.path.isdir(os.path.join(d, n)):
names.add(n)
return names
def layout_block(path):
"""(first line, text) of the first fenced block of a markdown file that starts with src/Formats/"""
lines = open(path, encoding="utf-8").read().split("\n")
for i, line in enumerate(lines):
if line.startswith("```") and i + 1 < len(lines) and lines[i + 1].startswith("src/Formats/"):
j = i + 1
while j < len(lines) and not lines[j].startswith("```"):
j += 1
return i + 1, "\n".join(lines[i + 1:j])
return 1, ""
modules = []
for dom in sorted(os.listdir(os.path.join(SRC, "codecs"))):
modules += ["codecs/%s/%s" % (dom, n) for n in sorted(module_names("codecs/" + dom))]
modules += ["containers/" + n for n in sorted(module_names("containers"))]
modules += ["core/" + n for n in sorted(module_names("core"))]
for doc in ("README.md", os.path.join("docs", "STYLE.md")):
path = os.path.join(ROOT, doc)
ln, block = layout_block(path)
if not block:
bad(path, 1, "DOCS: no layout block (a ``` block starting with src/Formats/)")
continue
for m in modules:
if not re.search(r"(?<![\w/])" + re.escape(m.rsplit("/", 1)[1]) + r"\b", block):
bad(path, ln, "DOCS: the layout block does not list %s" % m)
LABELS = {"image": "images", "audio": "audio", "video": "video", "model": "3D models", "cad": "CAD", "font": "fonts",
"archive": "archives", "data": "data", "vector": "vector graphics and tile maps", "layered": "layered images",
"subtitle": "subtitles", "music": "music", "playlist": "playlists"}
counts = {}
for line in open(os.path.join(ROOT, "docs", "FORMATS.md"), encoding="utf-8"):
cells = [c.strip() for c in line.split("|")]
if len(cells) > 3 and cells[1] in LABELS:
counts[cells[1]] = counts.get(cells[1], 0) + 1
readme = os.path.join(ROOT, "README.md")
rtext = open(readme, encoding="utf-8").read()
m = re.search(r"(\d+) formats:", rtext)
if not m or int(m.group(1)) != sum(counts.values()):
bad(readme, 1, "DOCS: README.md should say \"%d formats:\" (docs/FORMATS.md)" % sum(counts.values()))
for cat, label in LABELS.items():
m = re.search(r"\s+".join(map(re.escape, label.split())) + r"\s+\((\d+)\)", rtext)
if not m or int(m.group(1)) != counts.get(cat, 0):
bad(readme, 1, "DOCS: README.md should say \"%s (%d)\" (docs/FORMATS.md)" % (label, counts.get(cat, 0)))
guide = os.path.join(ROOT, "docs", "guide")
gindex = open(os.path.join(guide, "README.md"), encoding="utf-8").read()
for n in sorted(os.listdir(guide)):
if n.endswith(".md") and n != "README.md" and "](%s" % n not in gindex:
bad(os.path.join(guide, "README.md"), 1, "DOCS: the guide index does not link %s" % n)
print("\n".join(out))
sys.exit(1 if out else 0)