Files
rosetta/src/Formats/host/init.luau
T

44 lines
1.3 KiB
Luau

--!strict
-- host: the runtime adapter, detected once at load time. Roblox (no file system; toEditableImage), LÖVE
-- (love.filesystem + io; toImageData / toSoundData), plain LuaJIT (io), the Luau CLI (no file system).
--
-- local host = require("@formats/host")
-- print(host.name) -- "roblox" | "love" | "luajit" | "luau"
-- local buf, err = host.readFile("a.png") -- every host has readFile / writeFile / exists (failing with Err.IO
-- -- where there is no file system)
local Err = require("@formats/core/Err")
export type Host = {
name: string,
hasFiles: boolean,
readFile: (path: string) -> (buffer?, Err.Err?),
writeFile: (path: string, data: buffer) -> (boolean, Err.Err?),
exists: (path: string) -> boolean,
[string]: any,
}
local G = _G :: any
local name
if typeof(game) == "Instance" then
name = "roblox"
elseif G.love ~= nil and type(G.love) == "table" and G.love.filesystem ~= nil then
name = "love"
elseif G.jit ~= nil or G.io ~= nil then
name = "luajit"
else
name = "luau"
end
local host: Host
if name == "roblox" then
host = require("@formats/host/Roblox")
elseif name == "love" then
host = require("@formats/host/Love")
elseif name == "luajit" then
host = require("@formats/host/LuaJIT")
else
host = require("@formats/host/Luau")
end
local _ = Err
return host