From 695ac926edbd4792266722d903c719df63d0b330 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Tue, 8 Jan 2019 22:11:49 +1100 Subject: [PATCH] fix some bugs with io.lua, expose io.newfd() --- module/io.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module/io.lua b/module/io.lua index 859a14d..daa6ea1 100644 --- a/module/io.lua +++ b/module/io.lua @@ -26,7 +26,7 @@ local function fdc(f) fd[f.fd].close() fd[f.fd] = nil end -local function newfd() +function io.newfd() -- creates a new file descriptor and returns it plus its ID local nfd=#fd+1 fd[nfd] = {} return nfd,fd[nfd] @@ -34,10 +34,10 @@ end function io.open(f,m) -- opens file *f* with mode *m* local t={["close"]=fdc} 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 fobj then - local fdi,nfd = newfd() + local fdi,nfd = io.newfd() f=fdi if fobj.write then function nfd.write(d)