diff options
author | Marius <mariausol@gmail.com> | 2012-12-29 00:00:16 +0200 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2012-12-29 00:00:16 +0200 |
commit | f8d3835211dbbac2ed31376d655642571db52f4e (patch) | |
tree | 81017e6a4f1c5351cf2bc4d3b15a1b838e4394e4 /tex/context/base/l-io.lua | |
parent | 290581646ba1e91eb2be7086ec32653d1a33841f (diff) | |
download | context-f8d3835211dbbac2ed31376d655642571db52f4e.tar.gz |
beta 2012.12.28 20:30
Diffstat (limited to 'tex/context/base/l-io.lua')
-rw-r--r-- | tex/context/base/l-io.lua | 58 |
1 files changed, 31 insertions, 27 deletions
diff --git a/tex/context/base/l-io.lua b/tex/context/base/l-io.lua index e7bc23642..e48b448c5 100644 --- a/tex/context/base/l-io.lua +++ b/tex/context/base/l-io.lua @@ -59,7 +59,7 @@ io.readall = readall function io.loaddata(filename,textmode) -- return nil if empty local f = io.open(filename,(textmode and 'r') or 'rb') if f then - -- local data = f:read('*all') +-- local data = f:read('*all') local data = readall(f) f:close() if #data > 0 then @@ -88,29 +88,29 @@ end function io.loadlines(filename,n) -- return nil if empty local f = io.open(filename,'r') - if f then - if n then - local lines = { } - for i=1,n do - local line = f:read("*lines") - if line then - lines[#lines+1] = line - else - break - end - end - f:close() - lines = concat(lines,"\n") - if #lines > 0 then - return lines - end - else - local line = f:read("*line") or "" - assert(f:close()) - if #line > 0 then - return line + if not f then + -- no file + elseif n then + local lines = { } + for i=1,n do + local line = f:read("*lines") + if line then + lines[#lines+1] = line + else + break end end + f:close() + lines = concat(lines,"\n") + if #lines > 0 then + return lines + end + else + local line = f:read("*line") or "" + f:close() + if #line > 0 then + return line + end end end @@ -130,7 +130,7 @@ function io.exists(filename) if f == nil then return false else - assert(f:close()) + f:close() return true end end @@ -141,7 +141,7 @@ function io.size(filename) return 0 else local s = f:seek("end") - assert(f:close()) + f:close() return s end end @@ -149,9 +149,13 @@ end function io.noflines(f) if type(f) == "string" then local f = io.open(filename) - local n = f and io.noflines(f) or 0 - assert(f:close()) - return n + if f then + local n = f and io.noflines(f) or 0 + f:close() + return n + else + return 0 + end else local n = 0 for _ in f:lines() do |