ws-cleanup-types: Types, api, host: honest annotations; return the full annotated value count

This commit is contained in:
4DBug committed 2026-10-31 10:43:19 -05:00
1 parent 59a0352ca6
commit f209801579
22 files changed
+147 -147

No files matched your search

+9 -9
View File
@@ -31,7 +31,7 @@ function Host.readFile(path: string): (buffer?, Err.Err?)
if type(s) ~= "string" then
return nil, Err.new(Err.IO, "cannot read " .. path .. ": " .. tostring(msg))
end
return buffer.fromstring(s)
return buffer.fromstring(s), nil
end
local f, msg = io().open(path, "rb")
if not f then
@@ -39,7 +39,7 @@ function Host.readFile(path: string): (buffer?, Err.Err?)
end
local s = f:read("*a")
f:close()
return buffer.fromstring(s)
return buffer.fromstring(s), nil
end
-- writeFile: relative paths go to the save directory (love.filesystem.write), absolute ones through io
@@ -50,7 +50,7 @@ function Host.writeFile(path: string, data: buffer): (boolean, Err.Err?)
if not ok then
return false, Err.new(Err.IO, "cannot write " .. path .. ": " .. tostring(msg))
end
return true
return true, nil
end
local f, msg = io().open(path, "wb")
if not f then
@@ -58,7 +58,7 @@ function Host.writeFile(path: string, data: buffer): (boolean, Err.Err?)
end
f:write(s)
f:close()
return true
return true, nil
end
function Host.exists(path: string): boolean
@@ -79,8 +79,8 @@ function Host.toImageData(img: any): (any, Err.Err?)
return nil, Err.new(Err.ARG, "toImageData: needs rgba8 pixels, got " .. tostring(img.format))
end
local n = img.width * img.height * 4
local F = ffi()
local B = buffer :: any
local F: any = ffi()
local B: { toffi: ((buffer) -> any)? } = buffer :: any
if F and B.toffi then
local id = love().image.newImageData(img.width, img.height, "rgba8")
F.copy(id:getFFIPointer(), B.toffi(img.pixels), n)
@@ -94,8 +94,8 @@ end
function Host.fromImageData(id: any): Types.Image
local w, h = id:getDimensions()
local img = Types.Image.new(w, h, "rgba8")
local F = ffi()
local B = buffer :: any
local F: any = ffi()
local B: { toffi: ((buffer) -> any)? } = buffer :: any
if F and B.toffi and id:getFormat() == "rgba8" then
F.copy(B.toffi(img.pixels), id:getFFIPointer(), w * h * 4)
return img
@@ -131,7 +131,7 @@ function Host.toSoundData(a: any): (any, Err.Err?)
end
local sd = love().sound.newSoundData(math.max(frames, 1), rate, 16, channels)
local count = frames * channels
local F = ffi()
local F: any = ffi()
if F then
local p = F.cast("int16_t*", sd:getFFIPointer())
for i = 0, count - 1 do
+4 -4
View File
@@ -31,13 +31,13 @@ end
local host: Host
if name == "roblox" then
host = require("@formats/host/Roblox")
host = require("@formats/host/Roblox") :: any
elseif name == "love" then
host = require("@formats/host/Love")
host = require("@formats/host/Love") :: any
elseif name == "luajit" then
host = require("@formats/host/LuaJIT")
host = require("@formats/host/LuaJIT") :: any
else
host = require("@formats/host/Luau")
host = require("@formats/host/Luau") :: any
end
-- LuaJIT (plain or LÖVE): the big decoders (Opus CELT, H.264, ...) outgrow the default 1000 traces / 8 MB of machine
-- code and fall back to the interpreter (CELT runs about 2.5x faster with these limits). Raising the limits only