formats-luau foundation: build (darklua + token passes) for Roblox and LuaJIT, compat prelude, core, Types, host adapters, API + registry, lint, tests on both runtimes; absorb deflate (codecs/Deflate + new compressor) and png (image/png + new encoder)
This commit is contained in:
commit
cdcb5b0b77
226 files changed
+8409
No files matched your search
@@ -0,0 +1,40 @@
|
||||
--!strict
|
||||
-- host/Roblox: no file system (sources are buffers or strings, e.g. from HttpService or an asset); converts the
|
||||
-- standard types to engine objects:
|
||||
-- host.toEditableImage(img) -> EditableImage (rgba8; other formats are converted by the caller first)
|
||||
local Err = require("@formats/core/Err")
|
||||
|
||||
local Host = {}
|
||||
Host.name = "roblox"
|
||||
Host.hasFiles = false
|
||||
|
||||
function Host.readFile(path: string): (buffer?, Err.Err?)
|
||||
return nil, Err.new(Err.IO, "Roblox has no file system: pass a buffer or a string, not the path " .. path)
|
||||
end
|
||||
|
||||
function Host.writeFile(path: string, _data: buffer): (boolean, Err.Err?)
|
||||
return false, Err.new(Err.IO, "Roblox has no file system: cannot write " .. path .. " (use F.save(value) for a buffer)")
|
||||
end
|
||||
|
||||
function Host.exists(_path: string): boolean
|
||||
return false
|
||||
end
|
||||
|
||||
-- toEditableImage(img) -> EditableImage | nil, Err. img.format must be "rgba8".
|
||||
function Host.toEditableImage(img: any): (any, Err.Err?)
|
||||
if img.format ~= "rgba8" then
|
||||
return nil, Err.new(Err.ARG, "toEditableImage: needs rgba8 pixels, got " .. tostring(img.format))
|
||||
end
|
||||
local AssetService = (game :: any):GetService("AssetService")
|
||||
local size = Vector2.new(img.width, img.height)
|
||||
local ok, ei = pcall(function()
|
||||
return AssetService:CreateEditableImage({ Size = size })
|
||||
end)
|
||||
if not ok or not ei then
|
||||
return nil, Err.new(Err.IO, "CreateEditableImage failed: " .. tostring(ei))
|
||||
end
|
||||
ei:WritePixelsBuffer(Vector2.zero, size, img.pixels)
|
||||
return ei
|
||||
end
|
||||
|
||||
return Host
|
||||
Reference in new issue
Block a user