docs: rosetta naming in README, docs, guide, licenses
This commit is contained in:
1 parent
22ddcd78fa
commit
753ae98d4a
20 files changed
+123
-123
No files matched your search
+16
-16
@@ -1,6 +1,6 @@
|
||||
# formats-luau guide
|
||||
# rosetta guide
|
||||
|
||||
formats-luau reads, writes and converts file formats in pure Luau. One source tree runs on Roblox, on LuaJIT / LÖVE
|
||||
rosetta reads, writes and converts file formats in pure Luau. One source tree runs on Roblox, on LuaJIT / LÖVE
|
||||
and in the luau CLI. Each format maps onto the standard type of its category, so a PNG and a WebP both load as the
|
||||
same `Image`, and every audio format opens as the same streaming `Decoder`.
|
||||
|
||||
@@ -44,15 +44,15 @@ as `F`, and its input files as variables such as `pngBytes` (a buffer) or `srtTe
|
||||
**Roblox (Rojo).** Build the Roblox tree, then let Rojo turn it into a model or sync it into Studio:
|
||||
|
||||
```sh
|
||||
python3 -I tools/build.py roblox # writes build/roblox/Formats (requires become instance paths)
|
||||
rojo build -o Formats.rbxm # default.project.json mounts build/roblox/Formats; or: rojo serve
|
||||
python3 -I tools/build.py roblox # writes build/roblox/Rosetta (requires become instance paths)
|
||||
rojo build -o Rosetta.rbxm # default.project.json mounts build/roblox/Rosetta; or: rojo serve
|
||||
```
|
||||
|
||||
Put the `Formats` ModuleScript somewhere both client and server can see it, for example ReplicatedStorage:
|
||||
Put the `Rosetta` ModuleScript somewhere both client and server can see it, for example ReplicatedStorage:
|
||||
|
||||
<!-- doc:display needs Roblox -->
|
||||
```luau
|
||||
local F = require(game:GetService("ReplicatedStorage").Formats)
|
||||
local F = require(game:GetService("ReplicatedStorage").Rosetta)
|
||||
```
|
||||
|
||||
Roblox has no file system: pass buffers or strings, for example from `HttpService:GetAsync` or a `buffer` you built.
|
||||
@@ -60,27 +60,27 @@ Roblox has no file system: pass buffers or strings, for example from `HttpServic
|
||||
**LuaJIT and LÖVE.** Build the Lua 5.1 tree:
|
||||
|
||||
```sh
|
||||
python3 -I tools/build.py luajit # writes build/luajit/formats/ (plain Lua 5.1 + the LuaJIT FFI)
|
||||
python3 -I tools/build.py luajit # writes build/luajit/rosetta/ (plain Lua 5.1 + the LuaJIT FFI)
|
||||
```
|
||||
|
||||
Then either copy `build/luajit/formats` into your game, or put the build on `package.path`:
|
||||
Then either copy `build/luajit/rosetta` into your game, or put the build on `package.path`:
|
||||
|
||||
<!-- doc:display plain LuaJIT code -->
|
||||
```lua
|
||||
package.path = "build/luajit/?.lua;build/luajit/?/init.lua;" .. package.path
|
||||
local F = require("formats")
|
||||
local F = require("rosetta")
|
||||
```
|
||||
|
||||
The library carries its own copy of the Luau standard library pieces it uses (`buffer`, `bit32`, `utf8`, ...).
|
||||
Your own code gets them as globals with `require("formats._compat").install()`, which is useful when you read the
|
||||
Your own code gets them as globals with `require("rosetta._compat").install()`, which is useful when you read the
|
||||
pixel buffers yourself. [examples/love](../../examples/love/main.lua) is a runnable LÖVE example.
|
||||
|
||||
**luau CLI.** The repository's `.luaurc` defines the alias `@formats` for `src/Formats`, so a script run from the
|
||||
**luau CLI.** The repository's `.luaurc` defines the alias `@rosetta` for `src/Rosetta`, so a script run from the
|
||||
repository root can require the sources directly. The CLI has no file system.
|
||||
|
||||
<!-- doc:display a top-level require -->
|
||||
```luau
|
||||
local F = require("@formats")
|
||||
local F = require("@rosetta")
|
||||
```
|
||||
|
||||
The runnable programs in [examples/](../../examples) work this way: `luau examples/image.luau`.
|
||||
@@ -336,7 +336,7 @@ and `toSoundData` turns an `Audio` or a `Decoder` (read to its end) into 16-bit
|
||||
|
||||
<!-- doc:display needs LÖVE -->
|
||||
```lua
|
||||
local F = require("formats")
|
||||
local F = require("rosetta")
|
||||
local img = assert(F.load("sprite.png")) -- love.filesystem path
|
||||
local texture = love.graphics.newImage(F.host.toImageData(img))
|
||||
local music = love.audio.newSource(F.host.toSoundData(F.audio.open("music.ogg")), "static")
|
||||
@@ -347,13 +347,13 @@ F.save(shot, "shot.png") -- to the save directory
|
||||
|
||||
**LuaJIT trace limits.** When the library loads on LuaJIT it raises the JIT's trace limits
|
||||
(`jit.opt.start("maxtrace=8000", "maxmcode=65536")`). The big decoders (Opus CELT, VP8, H.264, MPEG-1) outgrow the
|
||||
defaults and fall back to the interpreter, which is 2x or more slower. Set `FORMATS_NO_JIT_TUNE` before the first
|
||||
defaults and fall back to the interpreter, which is 2x or more slower. Set `ROSETTA_NO_JIT_TUNE` before the first
|
||||
`require` to leave the JIT settings alone:
|
||||
|
||||
<!-- doc:display plain LuaJIT code -->
|
||||
```lua
|
||||
FORMATS_NO_JIT_TUNE = true -- a global, read once when the library loads
|
||||
local F = require("formats")
|
||||
ROSETTA_NO_JIT_TUNE = true -- a global, read once when the library loads
|
||||
local F = require("rosetta")
|
||||
```
|
||||
|
||||
## Conventions
|
||||
|
||||
@@ -150,10 +150,10 @@ local zip = F.format("zip").create()
|
||||
zip:add("assets/", nil) -- a directory
|
||||
zip:add("assets/hello.txt", "hello", { level = 9, mtime = 1767225600 })
|
||||
zip:add("assets/raw.bin", buffer.create(1024), { method = "store" })
|
||||
local bytes = assert(F.save(zip, nil, { format = "zip", comment = "made by formats-luau" }))
|
||||
local bytes = assert(F.save(zip, nil, { format = "zip", comment = "made by rosetta" }))
|
||||
|
||||
local back = assert(F.archive.load(bytes))
|
||||
assert(#back:list() == 3 and back.meta.comment == "made by formats-luau")
|
||||
assert(#back:list() == 3 and back.meta.comment == "made by rosetta")
|
||||
assert(back:list()[3].method == "store")
|
||||
assert(back:remove("assets/raw.bin") and #back:list() == 2)
|
||||
|
||||
@@ -350,7 +350,7 @@ stored data); ARJ and Zoo are read only.
|
||||
```luau
|
||||
local lzh = assert(F.archive.load(lzhBytes))
|
||||
assert(lzh.format == "lha" and lzh:list()[1].method == "lh0") -- small files are stored
|
||||
assert(buffer.tostring(assert(lzh:read("readme.txt"))) == "formats-luau retro archives\n")
|
||||
assert(buffer.tostring(assert(lzh:read("readme.txt"))) == "rosetta retro archives\n")
|
||||
local arj = assert(F.archive.load(arjBytes))
|
||||
assert(arj:read("src/main.c"))
|
||||
local zoo = assert(F.archive.load(zooBytes))
|
||||
|
||||
+3
-3
@@ -8,7 +8,7 @@ used the same way.
|
||||
```luau
|
||||
local song = assert(F.audio.load(flacBytes)) -- Audio: the whole file decoded
|
||||
print(song.sampleRate, song.channels, song.frames) -- 44100 2 44100
|
||||
print(song.tags.title, song.tags.artist) -- Docs Tone formats-luau
|
||||
print(song.tags.title, song.tags.artist) -- Docs Tone rosetta
|
||||
local quieter = F.ops.audio.gainDb(song, -6)
|
||||
local mp3 = assert(F.save(quieter, nil, { format = "mp3", bitrate = 192000 })) -- a buffer
|
||||
assert(F.detect(mp3) == "mp3")
|
||||
@@ -225,7 +225,7 @@ source can be fed block by block:
|
||||
|
||||
<!-- doc:display needs LÖVE -->
|
||||
```lua
|
||||
local F = require("formats")
|
||||
local F = require("rosetta")
|
||||
local sd = F.host.toSoundData(F.audio.load("music.flac")) -- whole file
|
||||
love.audio.newSource(sd):play()
|
||||
|
||||
@@ -313,7 +313,7 @@ assert(wv.bitsPerSample == 16 and wv.lossless and wv.tags.title == "Docs Tone")
|
||||
local exact, n = wv:readInt(1024) -- i32 samples, as wvunpack writes them
|
||||
assert(n == 1024 and buffer.readi32(exact, 0) == 0)
|
||||
local ape = assert(F.audio.load(apeBytes)) -- any level, fast .. insane
|
||||
assert(ape.meta.source.format == "ape" and ape.tags.artist == "formats-luau")
|
||||
assert(ape.meta.source.format == "ape" and ape.tags.artist == "rosetta")
|
||||
local tta = assert(F.audio.open(ttaBytes))
|
||||
tta:seek(0.5)
|
||||
assert(math.abs(tta:position() - 0.5) < 1e-6)
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ STEP files (ISO 10303-21, "Part 21": AP203, AP214, AP242 and any other schema) l
|
||||
its *entity graph*, every `#id = TYPE(...)` instance with its arguments, exactly as written. Reading and writing the
|
||||
graph is built in and lossless (parse, write, parse gives the same entities).
|
||||
|
||||
Turning the graph into solid geometry needs a B-rep kernel, which formats-luau does not include: B-rep bodies and
|
||||
Turning the graph into solid geometry needs a B-rep kernel, which rosetta does not include: B-rep bodies and
|
||||
tessellated meshes come from a plug-in you inject as `F.plugins.brep` (for example
|
||||
brep-luau's modules). Without it, `F.cad.toBodies` / `fromBodies` / `tessellate` return
|
||||
`UNSUPPORTED` and everything else on this page still works.
|
||||
|
||||
+2
-2
@@ -277,7 +277,7 @@ An animated image also opens as a video (`F.video.open(gifBytes)`), and saves to
|
||||
|
||||
<!-- doc:display Roblox only -->
|
||||
```luau
|
||||
local F = require(game.ReplicatedStorage.Formats)
|
||||
local F = require(game.ReplicatedStorage.Rosetta)
|
||||
local img = assert(F.image.load(pngBuffer)) -- e.g. from HttpService:GetAsync(...)
|
||||
local editable = assert(F.host.toEditableImage(img)) -- needs rgba8: F.ops.image.convert first otherwise
|
||||
local label = Instance.new("ImageLabel")
|
||||
@@ -286,7 +286,7 @@ label.ImageContent = Content.fromObject(editable)
|
||||
|
||||
<!-- doc:display LÖVE only -->
|
||||
```lua
|
||||
local F = require("formats")
|
||||
local F = require("rosetta")
|
||||
local img = assert(F.load("photo.png")) -- love.filesystem path
|
||||
local image = love.graphics.newImage(F.host.toImageData(img))
|
||||
local back = F.host.fromImageData(love.image.newImageData("other.png")) -- ImageData -> rgba8 Image
|
||||
|
||||
+1
-1
@@ -132,7 +132,7 @@ Its only use is as `opts.soundfont` when rendering MIDI.
|
||||
|
||||
```luau
|
||||
local bank = assert(F.music.load(sf2Bytes))
|
||||
assert(bank.kind == "soundfont" and bank.info.name == "formats-luau test bank")
|
||||
assert(bank.kind == "soundfont" and bank.info.name == "rosetta test bank")
|
||||
for _, p in bank.presets do
|
||||
print(p.bank, p.preset, p.name) -- 0 0 Sine, ...
|
||||
end
|
||||
|
||||
@@ -77,7 +77,7 @@ end
|
||||
|
||||
<!-- doc:display needs Roblox -->
|
||||
```luau
|
||||
local F = require(game:GetService("ReplicatedStorage").Formats)
|
||||
local F = require(game:GetService("ReplicatedStorage").Rosetta)
|
||||
local bytes = game:GetService("HttpService"):GetAsync("https://example.com/cat.webp")
|
||||
local img = assert(F.image.load(bytes))
|
||||
if img.format ~= "rgba8" then
|
||||
@@ -94,7 +94,7 @@ label.Parent = game:GetService("Players").LocalPlayer.PlayerGui:WaitForChild("Sc
|
||||
|
||||
<!-- doc:display needs LÖVE -->
|
||||
```lua
|
||||
local F = require("formats")
|
||||
local F = require("rosetta")
|
||||
local image
|
||||
function love.load()
|
||||
local img = assert(F.load("cat.webp")) -- a love.filesystem path
|
||||
@@ -141,7 +141,7 @@ container calls them.
|
||||
```luau
|
||||
for _, bytes in { flacBytes, mp3Bytes, oggBytes } do
|
||||
local dec = assert(F.audio.open(bytes)) -- open reads the headers only
|
||||
assert(dec.tags.title == "Docs Tone" and dec.tags.artist == "formats-luau")
|
||||
assert(dec.tags.title == "Docs Tone" and dec.tags.artist == "rosetta")
|
||||
print(string.format("%s - %s (%.1f s, %d Hz)", dec.tags.artist, dec.tags.title, dec.duration, dec.sampleRate))
|
||||
end
|
||||
```
|
||||
|
||||
@@ -36,7 +36,7 @@ assert(F.detect(xml) == "rbxlx" and F.detect(placeBytes) == "rbxl")
|
||||
Property values keep the file's type, because a number alone could be an `Int32`, a `Float32` or an `Enum`. Arrays
|
||||
follow the argument order of the Roblox constructors, so `Vector3.new(table.unpack(v.value))` and
|
||||
`CFrame.new(table.unpack(v.value))` rebuild them in a game. The full list is in the header of
|
||||
`src/Formats/codecs/model/Rbx/init.luau`:
|
||||
`src/Rosetta/codecs/model/Rbx/init.luau`:
|
||||
|
||||
- **Text and numbers:** `String`, `BinaryString`, `ProtectedString`, `ContentId`, `SharedString` are strings.
|
||||
`Bool`, `Int32`, `Int64`, `Float32`, `Float64`, `Enum`, `BrickColor`, `Faces` and `Axes` are numbers and booleans.
|
||||
|
||||
+1
-1
@@ -236,7 +236,7 @@ assert(not string.find(buffer.tostring(plain), "KHR_draco", 1, true))
|
||||
```
|
||||
|
||||
Raw `.drc` files (and Draco data inside other formats) go through the codec itself:
|
||||
`require(Formats.codecs.model.Draco).decode(bytes)` returns `{ kind, numPoints, numFaces, indices, attributes }` with
|
||||
`require(Rosetta.codecs.model.Draco).decode(bytes)` returns `{ kind, numPoints, numFaces, indices, attributes }` with
|
||||
each attribute's values per point (`name`, `uniqueId`, `components`, `type`, `normalized`, `data`).
|
||||
|
||||
## Editing: `F.ops.mesh`
|
||||
|
||||
Reference in new issue
Block a user