forked from izaya/OC-PsychOS2
fix some bugs with io.lua, expose io.newfd()
This commit is contained in:
parent
0928241895
commit
695ac926ed
@ -26,7 +26,7 @@ local function fdc(f)
|
|||||||
fd[f.fd].close()
|
fd[f.fd].close()
|
||||||
fd[f.fd] = nil
|
fd[f.fd] = nil
|
||||||
end
|
end
|
||||||
local function newfd()
|
function io.newfd() -- creates a new file descriptor and returns it plus its ID
|
||||||
local nfd=#fd+1
|
local nfd=#fd+1
|
||||||
fd[nfd] = {}
|
fd[nfd] = {}
|
||||||
return nfd,fd[nfd]
|
return nfd,fd[nfd]
|
||||||
@ -34,10 +34,10 @@ end
|
|||||||
function io.open(f,m) -- opens file *f* with mode *m*
|
function io.open(f,m) -- opens file *f* with mode *m*
|
||||||
local t={["close"]=fdc}
|
local t={["close"]=fdc}
|
||||||
if type(f) == "string" then
|
if type(f) == "string" then
|
||||||
local e,fobj=fs.open(f,m)
|
local e,fobj=pcall(fs.open,f,m)
|
||||||
if not e then return false, fobj end
|
if not e then return false, fobj end
|
||||||
if fobj then
|
if fobj then
|
||||||
local fdi,nfd = newfd()
|
local fdi,nfd = io.newfd()
|
||||||
f=fdi
|
f=fdi
|
||||||
if fobj.write then
|
if fobj.write then
|
||||||
function nfd.write(d)
|
function nfd.write(d)
|
||||||
|
Loading…
Reference in New Issue
Block a user