ws-cleanup: merge ws/cleanup-types (type annotations)
This commit is contained in:
commit
5d7c223ab8
115 files changed
+583
-515
No files matched your search
+15
-15
@@ -96,7 +96,7 @@ local function detect(buf: buffer, name: string?, category: string?, format: str
|
||||
if not e then
|
||||
return nil, Err.new(Err.UNKNOWN_FORMAT, "no format named " .. format .. (if category then " in " .. category else ""))
|
||||
end
|
||||
return e
|
||||
return e, nil
|
||||
end
|
||||
local ext = Input.extension(name)
|
||||
local best: Registry.Entry? = nil
|
||||
@@ -118,12 +118,12 @@ local function detect(buf: buffer, name: string?, category: string?, format: str
|
||||
end
|
||||
end
|
||||
if best then
|
||||
return best
|
||||
return best, nil
|
||||
end
|
||||
if ext then
|
||||
local e = find(ext, category)
|
||||
if e then
|
||||
return e
|
||||
return e, nil
|
||||
end
|
||||
end
|
||||
return nil, Err.new(Err.UNKNOWN_FORMAT, "unrecognised data" .. (if name then " (" .. name .. ")" else "") .. (if category then " for " .. category else ""))
|
||||
@@ -197,7 +197,7 @@ local function pageLoader(value: any, name: string?, o: Options)
|
||||
if type(value) ~= "table" or value.kind ~= "font" or type(value.meta) ~= "table" or type(value.meta.pageFiles) ~= "table" then
|
||||
return
|
||||
end
|
||||
local user = o.loadPage
|
||||
local user: any = o.loadPage
|
||||
if value.pages or (value.meta.pageLoader and type(user) ~= "function") then
|
||||
return
|
||||
end
|
||||
@@ -208,7 +208,7 @@ local function pageLoader(value: any, name: string?, o: Options)
|
||||
value.meta.pageLoader = function(file: string, page: number): (any, Err.Err?)
|
||||
local src: any
|
||||
if type(user) == "function" then
|
||||
src = user(file, page)
|
||||
src = (user :: any)(file, page)
|
||||
else
|
||||
src = (dir :: string) .. file
|
||||
end
|
||||
@@ -305,7 +305,7 @@ end
|
||||
|
||||
-- load(src, opts?) -> value | nil, Err
|
||||
function F.load(src: any, opts: Options?): (any, Err.Err?)
|
||||
local o = opts or {}
|
||||
local o: Options = opts or {}
|
||||
local buf, ierr, name = Input.resolve(src, o, host)
|
||||
if not buf then
|
||||
return nil, ierr
|
||||
@@ -357,7 +357,7 @@ load = F.load
|
||||
|
||||
-- open(src, opts?) -> a streaming decoder (audio Decoder / VideoDecoder / Demuxer) | nil, Err
|
||||
function F.open(src: any, opts: Options?): (any, Err.Err?)
|
||||
local o = opts or {}
|
||||
local o: Options = opts or {}
|
||||
local buf, ierr, name = Input.resolve(src, o, host)
|
||||
if not buf then
|
||||
return nil, ierr
|
||||
@@ -454,7 +454,7 @@ end
|
||||
|
||||
-- save(value, dest?, opts?) -> buffer (no dest) | true (written to dest) | nil, Err
|
||||
function F.save(value: any, dest: string?, opts: Options?): (any, Err.Err?)
|
||||
local o = opts or {}
|
||||
local o: Options = opts or {}
|
||||
local entry, m, err, key = encoderFor(value, dest, o)
|
||||
if not entry then
|
||||
return nil, err
|
||||
@@ -514,12 +514,12 @@ function F.saveString(value: any, opts: Options?): (string?, Err.Err?)
|
||||
if not buf then
|
||||
return nil, err
|
||||
end
|
||||
return buffer.tostring(buf)
|
||||
return buffer.tostring(buf), nil
|
||||
end
|
||||
|
||||
-- convert(src, format, opts?) -> buffer (or true with opts.out = a path) | nil, Err. opts go to both load and save.
|
||||
function F.convert(src: any, format: string, opts: Options?): (any, Err.Err?)
|
||||
local o = opts or {}
|
||||
local o: Options = opts or {}
|
||||
local value, err = F.load(src, o)
|
||||
if value == nil then
|
||||
return nil, err
|
||||
@@ -532,7 +532,7 @@ end
|
||||
|
||||
-- detect(src, opts?) -> format name | nil, Err
|
||||
function F.detect(src: any, opts: Options?): (string?, Err.Err?)
|
||||
local o = opts or {}
|
||||
local o: Options = opts or {}
|
||||
local buf, ierr, name = Input.resolve(src, o, host)
|
||||
if not buf then
|
||||
return nil, ierr
|
||||
@@ -541,7 +541,7 @@ function F.detect(src: any, opts: Options?): (string?, Err.Err?)
|
||||
if not entry then
|
||||
return nil, err
|
||||
end
|
||||
return entry.name
|
||||
return entry.name, nil
|
||||
end
|
||||
|
||||
export type FormatInfo = { name: string, category: string, extensions: { string }, mime: { string }, caps: { [string]: any } }
|
||||
@@ -569,7 +569,7 @@ end
|
||||
-- ------------------------------------------------------------------------------------------------ category facades
|
||||
-- F.image.load / save / open / formats, F.audio..., F.model... : the same calls restricted to one category
|
||||
local function with(opts: Options?, category: string): Options
|
||||
local o = if opts then table.clone(opts) else {}
|
||||
local o: Options = if opts then table.clone(opts) else {}
|
||||
o.category = category
|
||||
return o
|
||||
end
|
||||
@@ -598,7 +598,7 @@ F.data.null = Types.null
|
||||
for _, fn in { "toBodies", "fromBodies", "tessellate" } do
|
||||
local name: string = fn
|
||||
F.cad[name] = function(value: any, opts: Options?): (any, any)
|
||||
local o = if opts then table.clone(opts) else {}
|
||||
local o: Options = if opts then table.clone(opts) else {}
|
||||
if o.plugins == nil then
|
||||
o.plugins = F.plugins
|
||||
end
|
||||
@@ -660,7 +660,7 @@ F.model.loadTextures = function(scene: any, opts: Options?): (any, { [number]: E
|
||||
if type(scene) ~= "table" or type(scene.textures) ~= "table" then
|
||||
return scene, errs
|
||||
end
|
||||
local resolve = opts and opts.resolve
|
||||
local resolve: ((any) -> any)? = opts and opts.resolve
|
||||
for i, tex in scene.textures do
|
||||
if type(tex) == "table" and tex.image == nil then
|
||||
local data = tex.data
|
||||
|
||||
Reference in new issue
Block a user