along with this program. If not, see <http://www.gnu.org/licenses/>.
]]
-
-module("luafile", package.seeall)
+local luafile = {}
require("luafile_ll")
-function new()
+function luafile.new()
local f = {}
local meta = { __index = luafile }
setmetatable(f, meta)
return f
end
-function open(path, mode)
- local f = new()
+function luafile.open(path, mode)
+ local f = luafile.new()
f.file = luafile_ll.fopen(path, mode)
if f.file then
return f
return nil
end
-function fdopen(fd, mode)
- local f = new()
+function luafile.fdopen(fd, mode)
+ local f = luafile.new()
f.file = luafile_ll.fdopen(fd, mode)
if f.file then
return f
return nil
end
-function close(luafile)
+function luafile.close(luafile)
if luafile and luafile.file then
if luafile_ll.fclose(luafile.file) then
- file = nil
+ luafile.file = nil
return true
end
end
return false
end
-function read(luafile)
+function luafile.read(luafile)
if luafile and luafile.file then
return luafile_ll.fread(luafile.file)
end
return nil
end
-function write(luafile, buffer)
+function luafile.write(luafile, buffer)
if luafile and luafile.file and buffer then
return luafile_ll.fwrite(luafile.file, buffer)
end
return nil
end
-function readline(luafile)
+function luafile.readline(luafile)
if luafile and luafile.file then
return luafile_ll.fgets(luafile.file)
end
return nil
end
-function seek(luafile, offset)
+function luafile.seek(luafile, offset)
if luafile and luafile.file and offset then
return luafile_ll.fseek(luafile.file, offset)
end
return nil
end
-function flush(luafile)
+function luafile.flush(luafile)
if luafile and luafile.file then
return luafile_ll.fflush(luafile.file)
end
return nil
end
-function fileno(luafile)
+function luafile.fileno(luafile)
if luafile and luafile.file then
return luafile_ll.fileno(luafile.file)
end
return nil
end
-function eof(luafile)
+function luafile.eof(luafile)
if luafile and luafile.file then
return luafile_ll.feof(luafile.file)
end
return nil
end
-function setlinebuf(luafile)
+function luafile.setlinebuf(luafile)
if luafile and luafile.file then
return luafile_ll.setlinebuf(luafile.file)
end
return nil
end
-function pipe()
+function luafile.pipe()
local rc, r, w = luafile_ll.pipe()
local fr, fw
if not rc then
return false, nil, nil
end
- fr = fdopen(r, "r")
- fw = fdopen(w, "w")
+ fr = luafile.fdopen(r, "r")
+ fw = luafile.fdopen(w, "w")
return rc, fr, fw
end
-function dup2(oldfd, newfd)
+function luafile.dup2(oldfd, newfd)
if oldfd and newfd then
return luafile_ll.dup2(oldfd, newfd)
end
return nil
end
-
+return luafile