docs: rosetta naming in README, docs, guide, licenses

This commit is contained in:
4DBug committed 2026-11-01 01:19:16 -05:00
1 parent 22ddcd78fa
commit 753ae98d4a
20 files changed
+123 -123

No files matched your search

+21 -21
View File
@@ -1,4 +1,4 @@
# formats-luau style guide
# rosetta style guide
Every format looks the same: one folder, one contract, one test, one fixture generator, and the folder holds only what
is specific to the format (section 2a). `bash tools/lint.sh` enforces most of what follows (the rule names in
@@ -8,16 +8,16 @@ The reference implementation to copy is **PNG**:
| What | Copy from |
|---|---|
| Format contract (`init.luau`) | `src/Formats/image/png/init.luau` |
| Private hot submodules (`--!native`) | `src/Formats/image/png/Decode.luau`, `src/Formats/image/png/Encode.luau` |
| Format contract (`init.luau`) | `src/Rosetta/image/png/init.luau` |
| Private hot submodules (`--!native`) | `src/Rosetta/image/png/Decode.luau`, `src/Rosetta/image/png/Encode.luau` |
| Test | `tests/image/png.luau` |
| Fixture generator | `tools/fixtures/png.py` (a reference tool through nix: `tools/fixtures/_png_reference.py`) |
| A codec (layer 3) | `src/Formats/codecs/compress/Deflate/` + `tests/codecs/deflate.luau` + `tools/fixtures/deflate.py` |
| A codec (layer 3) | `src/Rosetta/codecs/compress/Deflate/` + `tests/codecs/deflate.luau` + `tools/fixtures/deflate.py` |
## 1. Layout and layers
```
src/Formats/
src/Rosetta/
init.luau Registry.luau (generated) api (layer 6)
ops/ ops (layer 5.5) editing on the standard types (F.ops.image /
mesh / layers / audio / music; ImageOps, ...)
@@ -49,9 +49,9 @@ Nothing but the api requires `host/`: formats are pure functions of bytes. A cod
(`codecs/<compress|entropy|image|audio|video|text|font|model>/<Name>`); `containers/` and `core/` are flat. Moving a
module: `python3 -I tools/move.py old/Path=new/Path` rewrites every reference (requires, deps, headers, docs).
REQUIRE: every require is a string literal `require("@formats/<path>")` (tests and tools may also use
REQUIRE: every require is a string literal `require("@rosetta/<path>")` (tests and tools may also use
`require("@tests/<path>")`). No `script.X`, no `@self`, no relative paths, no computed requires: `tools/build.py` turns
these literals into Roblox instance paths and `require("formats.x.y")` for LuaJIT. `@formats/image/png` is the folder's
these literals into Roblox instance paths and `require("rosetta.x.y")` for LuaJIT. `@rosetta/image/png` is the folder's
`init.luau`.
DEPS: a format's `deps = { ... }` lists exactly the modules outside its folder that the folder requires.
@@ -60,8 +60,8 @@ DEPS: a format's `deps = { ... }` lists exactly the modules outside its folder t
### Files
```
src/Formats/<category>/<fmt>/init.luau the contract (interpreted: never --!native)
src/Formats/<category>/<fmt>/<Private>.luau hot code, --!native allowed (Decode, Encode, Huffman tables, ...)
src/Rosetta/<category>/<fmt>/init.luau the contract (interpreted: never --!native)
src/Rosetta/<category>/<fmt>/<Private>.luau hot code, --!native allowed (Decode, Encode, Huffman tables, ...)
tests/<category>/<fmt>.luau the test (both runtimes)
tools/fixtures/<fmt>.py fixture generator (reference tools via nix) -> tests/gen/<fmt>_*.luau
```
@@ -73,7 +73,7 @@ tools/fixtures/<fmt>.py fixture generator (reference tools v
--!optimize 2 -- optional
-- image/png/Decode: <what it is>. <Spec / port origin>. <Supports / not supported>.
```
The first comment line starts with the module path (`core/Bytes:`, `image/png:`, `image/png/Decode:`; `Formats:` for
The first comment line starts with the module path (`core/Bytes:`, `image/png:`, `image/png/Decode:`; `Rosetta:` for
the root). A format's `init.luau` header says what is supported and what is not, and where it came from (spec, port,
absorbed repo).
@@ -86,10 +86,10 @@ contract are mandatory, the rest as needed):
### The contract
```luau
-- ------------------------------------------------------------------------------------------------ requires
local Err = require("@formats/core/Err")
local Bytes = require("@formats/core/Bytes")
local Types = require("@formats/Types")
local Decode = require("@formats/image/qoi/Decode")
local Err = require("@rosetta/core/Err")
local Bytes = require("@rosetta/core/Bytes")
local Types = require("@rosetta/Types")
local Decode = require("@rosetta/image/qoi/Decode")
-- ------------------------------------------------------------------------------------------------ contract
local Qoi = {
@@ -236,9 +236,9 @@ copying.
```luau
-- image/qoi tests: <what is covered>. Fixtures: tools/fixtures/qoi.py.
local T = require("@tests/T")
local Qoi = require("@formats/image/qoi")
local Bytes = require("@formats/core/Bytes")
local Crc32 = require("@formats/core/Crc32")
local Qoi = require("@rosetta/image/qoi")
local Bytes = require("@rosetta/core/Bytes")
local Crc32 = require("@rosetta/core/Crc32")
local Fx = require("@tests/gen/qoi") -- written by tools/fixtures/qoi.py
local t = T.suite("qoi")
@@ -272,13 +272,13 @@ t:done()
## 4. Adding a format
1. `src/Formats/<category>/<fmt>/init.luau` from the template above (copy `image/png/init.luau`), private submodules
1. `src/Rosetta/<category>/<fmt>/init.luau` from the template above (copy `image/png/init.luau`), private submodules
next to it. Use `core/Bytes` for parsing, `core/Bits` / `codecs/entropy/Huffman` for entropy coding, the shared
modules of section 2a for everything generic, `Types` constructors for the result.
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/Formats/Registry.luau` and `docs/FORMATS.md`; never edit those
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).
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).
@@ -296,7 +296,7 @@ making them (a missing `Bytes` method, a new `Types` field, a `Err` code).
2. Provenance: the module header says `Absorbed from <repo> <version> (<author / licence>)` and what changed.
3. Licence: copy the repo's licence / NOTICE into `licenses/` (`licenses/<repo>-LICENSE.txt`) and add a line to
`licenses/NOTICE.md`. Third-party ports keep their upstream licence text there too.
4. Requires: `if script then require(script.X) else require("@self/X")` becomes `require("@formats/<cat>/<fmt>/X")`;
4. Requires: `if script then require(script.X) else require("@self/X")` becomes `require("@rosetta/<cat>/<fmt>/X")`;
injected dependencies (`require(Png)(Deflate)`) become direct requires of the codec.
5. Checksums / bit readers / Huffman tables the repo carries are replaced by `core/` ones when equivalent.
6. Wrap the public API in the contract: `sniff`, `decode(r: Reader, opts)` (reading from `r.buf` between `r.base` and
@@ -317,7 +317,7 @@ cover what it cannot:
`elseif` to `else if` before darklua.
- **If-expression tables**: darklua lowers `if c then x else y` to `(c and {x} or {y})[1]` unless `x` is a literal.
build.py turns it back into `(c and (x) or (y))` when `x` is provably not nil/false (numbers, strings, arithmetic).
- **Requires** become `require("formats.a.b")`; **stdlib names** come from `formats._compat` through locals injected on
- **Requires** become `require("rosetta.a.b")`; **stdlib names** come from `rosetta._compat` through locals injected on
the first line of each module (only the ones used: LuaJIT allows 60 upvalues per function).
- `string.format("%s", x)` with interpolation and `tostring` of floats print differently on LuaJIT (14 significant
digits); never compare formatted floats in tests.