commented some io library functions

This commit is contained in:
Izaya 2020-03-20 13:01:50 +11:00
parent 3c1e2d31ae
commit 66ea129b7a
1 changed files with 7 additions and 7 deletions

View File

@ -1,12 +1,12 @@
io = {} io = {}
function io.open(path,mode) function io.open(path,mode) -- Open file *path* in *mode*. Returns a buffer object.
local f,e = fs.open(path, mode) local f,e = fs.open(path, mode)
if not f then return false, e end if not f then return false, e end
return buffer.new(mode,f) return buffer.new(mode,f)
end end
function io.input(fd) function io.input(fd) -- 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 if type(fd) == "string" then
fd=io.open(fd,"rb") fd=io.open(fd,"rb")
end end
@ -15,7 +15,7 @@ function io.input(fd)
end end
return os.getenv("STDIN") return os.getenv("STDIN")
end end
function io.output(fd) function io.output(fd) -- 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 if type(fd) == "string" then
fd=io.open(fd,"wb") fd=io.open(fd,"wb")
end end
@ -25,14 +25,14 @@ function io.output(fd)
return os.getenv("STDOUT") return os.getenv("STDOUT")
end end
function io.read(...) function io.read(...) -- Reads from the default input stream.
return io.input():read() return io.input():read(...)
end end
function io.write(...) function io.write(...) -- Writes its arguments to the default output stream.
io.output():write(...) io.output():write(...)
end end
function print(...) function print(...) -- Writes each argument to the default output stream, separated by newlines.
for k,v in ipairs({...}) do for k,v in ipairs({...}) do
io.write(tostring(v).."\n") io.write(tostring(v).."\n")
end end