mirror of
https://git.shadowkat.net/izaya/OC-PsychOS2.git
synced 2024-12-25 12:15:26 -05:00
41 lines
1.2 KiB
Lua
41 lines
1.2 KiB
Lua
io = {}
|
|
|
|
function io.open(path,mode) -- string string -- table -- Open file *path* in *mode*. Returns a buffer object.
|
|
local f,e = fs.open(path, mode)
|
|
if not f then return false, e end
|
|
return buffer.new(mode,f)
|
|
end
|
|
|
|
function io.input(fd) -- table -- table -- Sets the default input stream to *fd* if provided, either as a buffer as a path. Returns the default input stream.
|
|
if type(fd) == "string" then
|
|
fd=io.open(fd,"rbt")
|
|
end
|
|
if fd then
|
|
os.setenv("STDIN",fd)
|
|
end
|
|
return os.getenv("STDIN")
|
|
end
|
|
function io.output(fd) -- table -- table -- Sets the default output stream to *fd* if provided, either as a buffer as a path. Returns the default output stream.
|
|
if type(fd) == "string" then
|
|
fd=io.open(fd,"wb")
|
|
end
|
|
if fd then
|
|
os.setenv("STDOUT",fd)
|
|
end
|
|
return os.getenv("STDOUT")
|
|
end
|
|
|
|
function io.read(...) -- Reads from the default input stream.
|
|
return io.input():read(...)
|
|
end
|
|
function io.write(...) -- Writes its arguments to the default output stream.
|
|
io.output():write(...)
|
|
end
|
|
|
|
function print(...) -- Writes each argument to the default output stream, separated by space.
|
|
for k,v in ipairs({...}) do
|
|
io.write((k>1 and "\t" or "")..tostring(v))
|
|
end
|
|
io.write("\n")
|
|
end
|