api: lazy format detection (Sniffs.luau): F.detect loads no format module
tools/gen_registry.py now also writes src/Rosetta/Sniffs.luau: each format's sniff copied (tools/sniff_extract.py) with the top-level locals, types and load-time loops it reaches; requires outside core/ become proxies that require on first field access. 198 of 199 sniffs are copied (model/fbx reads Binary.MAGIC at load time: its module sniffs). Registry entries gain sniff (0 copy, 1 copy reaching a codec / container, 2 module) and variant (the module has variant(r)). init.luau detect: the extension's formats first, then by sniff cost and registry order; a sniff runs only while its cap (1, or LATE) could still win, ties to registry order, so results equal the eager path. F.detect loads the winner only when it has variant(). tests/detect.luau: every copied sniff against its module's on samples of every fixture module (tools/fixtures/detect.py), scores within 0..1, and F.detect against the eager reference with no name, the right / wrong / unknown extension and per category. Outside init / Registry / gen_registry: tools/fixtures.py (LAST generators run after the others and rerun when their outputs change), tools/lint_rules.py (Sniffs is api layer, skipped by DUP), docs/STYLE.md and docs/API.md notes, build/ regenerated.
This commit is contained in:
1 parent
dde6be117c
commit
e05392ee8e
18 files changed
+16513
-1466
No files matched your search
+1
-1
@@ -24,7 +24,7 @@ come back as a third value `{ [file name] = buffer }` (or in the caller's `opts.
|
||||
| `F.save(value, dest?, opts?)` | `buffer` / `true` (+ the extra files, see above) |
|
||||
| `F.saveString(value, opts?)` | the encoded bytes as a string |
|
||||
| `F.convert(src, format, opts?)` | load + save (`opts` go to both; `opts.out = path` writes a file) |
|
||||
| `F.detect(src, opts?)` | the format name (content sniffing first, then the extension); a format's optional `variant(r)` can name the flavour (`"webm"` for a WebM file read by mkv) |
|
||||
| `F.detect(src, opts?)` | the format name (content sniffing first, then the extension); a format's optional `variant(r)` can name the flavour (`"webm"` for a WebM file read by mkv). Sniffing loads no format module (the generated `Sniffs.luau`); `load` / `open` / `save` load only the format they use |
|
||||
| `F.formats(category?)` | `{ { name, category, extensions, mime, caps } }` without loading any format (also [FORMATS.md](FORMATS.md)) |
|
||||
| `F.format(name)` | the format module itself (`sniff` / `decode` / `encode` / `open` and extras such as `png.info`) |
|
||||
|
||||
|
||||
+8
-3
@@ -18,7 +18,7 @@ The reference implementation to copy is **PNG**:
|
||||
|
||||
```
|
||||
src/Rosetta/
|
||||
init.luau Registry.luau (generated) api (layer 6)
|
||||
init.luau Registry.luau Sniffs.luau (gen.) api (layer 6)
|
||||
ops/ ops (layer 5.5) editing on the standard types (F.ops.image /
|
||||
mesh / layers / audio / music; ImageOps, ...)
|
||||
<category>/<fmt>/ formats (layer 5) image audio video model cad font archive data
|
||||
@@ -156,6 +156,11 @@ Rules:
|
||||
inside a bigger buffer; never assume offset 0). It returns the category's standard type from `Types.luau`
|
||||
(`Types.Image.new(w, h)`, `Types.Scene.new()`, ...), `rgba8` for images unless `opts.native` asks for the source layout.
|
||||
Fill `meta.source = { format = "<name>", ... }` with the source facts (bit depth, colour type, codec, ...).
|
||||
- `sniff(r)` scores 0..1 and is copied, with the top-level locals, types and loops it reaches, into the generated
|
||||
`Sniffs.luau`, so detection requires no format module (requires outside `core/` become proxies loaded at sniff time).
|
||||
A sniff that reaches its module table (`Png.info(r)`), a forward-declared local or a load-time read of a non-core
|
||||
module is not copied: its module then loads on every detection that gets that far. `tests/detect.luau` checks the
|
||||
copies against the modules.
|
||||
- `encode(value, opts)` returns a buffer. Validate the value first and return `Err.ARG` for anything wrong.
|
||||
- `open(r, opts)` (audio / video) returns the streaming Decoder / VideoDecoder / Demuxer from `Types.luau`. If a format
|
||||
has `open` but no `decode`, `F.load` decodes the whole stream through it.
|
||||
@@ -312,8 +317,8 @@ t:done()
|
||||
2. Shared code (a codec two formats need, a container) goes to `codecs/<domain>/` or `containers/` instead, with its
|
||||
own test in `tests/codecs/` / `tests/containers/`.
|
||||
3. `deps = { ... }` = the requires outside the folder.
|
||||
4. `python3 -I tools/gen_registry.py` (regenerates `src/Rosetta/Registry.luau` and `docs/FORMATS.md`; never edit those
|
||||
by hand; after a merge, just rerun it).
|
||||
4. `python3 -I tools/gen_registry.py` (regenerates `src/Rosetta/Registry.luau`, `Sniffs.luau` and `docs/FORMATS.md`;
|
||||
never edit those by hand; after a merge, just rerun it).
|
||||
5. `tools/fixtures/<fmt>.py` + `tests/<category>/<fmt>.luau`.
|
||||
6. `bash tools/test.sh <fmt>` while working (both runtimes), then `bash tools/test.sh` (everything + lint).
|
||||
7. The docs line comes from the contract (`docs/FORMATS.md`); put format notes (limits, spec deviations, bench numbers)
|
||||
|
||||
Reference in new issue
Block a user