]> git.e2factory.org Git - e2factory.git/commitdiff
cleanup: turn luafile into a proper lua module
authorGordon Hecker <gh@emlix.com>
Thu, 21 Jan 2010 14:18:47 +0000 (15:18 +0100)
committerGordon Hecker <gh@emlix.com>
Fri, 12 Feb 2010 09:51:59 +0000 (10:51 +0100)
Signed-off-by: Gordon Hecker <gh@emlix.com>
generic/loader.lua
generic/luafile.lua
local/Makefile

index dfc04b7c1c91cb76f49316a208028763e1d05029..cd1ad755f54781ac9c088b7c024d5221cad5f5b6 100644 (file)
@@ -31,3 +31,4 @@ require("e2util")
 require("luafile_ll")
 
 require("e2option")
+require("luafile")
index fcddb6802705d5ebc12b19d038893147570578b8..cc0f63bc2bb9d9475ce3ce4f810597727b9dd6e4 100644 (file)
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ]]
 
-luafile = {}
 
-function luafile.new()
+module("luafile", package.seeall)
+
+function new()
   local f = {}
-  f.close = luafile.close
-  f.read = luafile.read
-  f.write = luafile.write
-  f.seek = luafile.seek
-  f.flush = luafile.flush
-  f.fileno = luafile.fileno
-  f.readline = luafile.readline
-  f.setlinebuf = luafile.setlinebuf
-  f.eof = luafile.eof
+  local meta = { __index = luafile }
+  setmetatable(f, meta)
   return f
 end
 
-function luafile.open(path, mode)
-  local f = luafile.new()
+function open(path, mode)
+  local f = new()
   f.file = luafile_ll.fopen(path, mode)
   if f.file then
     return f
@@ -50,8 +44,8 @@ function luafile.open(path, mode)
   return nil
 end
 
-function luafile.fdopen(fd, mode)
-  local f = luafile.new()
+function fdopen(fd, mode)
+  local f = new()
   f.file = luafile_ll.fdopen(fd, mode)
   if f.file then
     return f
@@ -59,84 +53,84 @@ function luafile.fdopen(fd, mode)
   return nil
 end
 
-function luafile.close(luafile)
+function close(luafile)
   if luafile and luafile.file then
     if luafile_ll.fclose(luafile.file) then
-      luafile.file = nil
+      file = nil
       return true
     end
   end
   return false
 end
 
-function luafile.read(luafile)
+function read(luafile)
   if luafile and luafile.file then
     return luafile_ll.fread(luafile.file)
   end
   return nil
 end
 
-function luafile.write(luafile, buffer)
+function write(luafile, buffer)
   if luafile and luafile.file and buffer then
     return luafile_ll.fwrite(luafile.file, buffer)
   end
   return nil
 end
 
-function luafile.readline(luafile)
+function readline(luafile)
   if luafile and luafile.file then
     return luafile_ll.fgets(luafile.file)
   end
   return nil
 end
 
-function luafile.seek(luafile, offset)
+function seek(luafile, offset)
   if luafile and luafile.file and offset then
     return luafile_ll.fseek(luafile.file, offset)
   end
   return nil
 end
 
-function luafile.flush(luafile)
+function flush(luafile)
   if luafile and luafile.file then
     return luafile_ll.fflush(luafile.file)
   end
   return nil
 end
 
-function luafile.fileno(luafile)
+function fileno(luafile)
   if luafile and luafile.file then
     return luafile_ll.fileno(luafile.file)
   end
   return nil
 end
 
-function luafile.eof(luafile)
+function eof(luafile)
   if luafile and luafile.file then
     return luafile_ll.feof(luafile.file)
   end
   return nil
 end
 
-function luafile.setlinebuf(luafile)
+function setlinebuf(luafile)
   if luafile and luafile.file then
     return luafile_ll.setlinebuf(luafile.file)
   end
   return nil
 end
 
-function luafile.pipe()
+function pipe()
   local rc, r, w = luafile_ll.pipe()
   local fr, fw
   if not rc then
     return false, nil, nil
   end
-  fr = luafile.fdopen(r, "r")
-  fw = luafile.fdopen(w, "w")
+  fr = fdopen(r, "r")
+  fw = fdopen(w, "w")
   return rc, fr, fw
 end
 
-function luafile.dup2(oldfd, newfd)
+function dup2(oldfd, newfd)
   if oldfd and newfd then
     return luafile_ll.dup2(oldfd, newfd)
   end
index 81bb73fd96bf0dd566de168198ff18fef8ba2b09..79cfce26975fab4cd7d74862b0ff8afd078ade83 100644 (file)
@@ -42,7 +42,7 @@ LOCALLUATOOLS = \
        build dlist dsort fetch-sources new-source ls-project \
        playground build-numbers cf
 LOCALSHTOOLS =
-LUA_LIBS = e2option.lua
+LUA_LIBS = e2option.lua luafile.lua
 LOCALTOOLS = $(LOCALSHTOOLS) $(LOCALLUATOOLS)
 
 SYMLINKS_2_1 = lookup-server use-source prepare-cargo sync-results cleanup \
@@ -62,12 +62,14 @@ install:
                ln -sf e2 $(DESTDIR)$(BINDIR)/e2-$$i ; \
        done
 
+install-local-dirs:
+       mkdir -p $(LOCALBINDIR) $(LOCALMAKDIR) $(LOCALLIBDIR)
+
 install-local-lua: $(LUA_LIBS)
        install -m 644 $^ $(LOCALLIBDIR)
 
-install-local: all install_sourcefiles install-local-lua
+install-local: all install-local-dirs install-local-lua install-local-sourcefiles
        test -n "$(PROJECTDIR)"
-       mkdir -p $(LOCALBINDIR) $(LOCALMAKDIR) $(LOCALLIBDIR)
        install -m 755 -d $(LOCALPLUGINDIR)
        install -m644 e2local.lc $(LOCALLIBDIR)/
        for i in $(LOCALLUATOOLS); do \
@@ -84,10 +86,8 @@ install-local: all install_sourcefiles install-local-lua
        install -m 755 luafile_ll.so $(LOCALLIBDIR)
        install -m 755 e2util.so $(LOCALLIBDIR)
 
-.PHONY: install_sourcefiles
-install_sourcefiles: e2-su-2.2.c
+install-local-sourcefiles: e2-su-2.2.c
        install -m 644 $^ $(LOCALMAKDIR)
-
 doc:
        for s in $(SUBDIRS) ; do \
                $(MAKE) -C $$s $@ ;\
@@ -131,7 +131,7 @@ e2local.lc: strict.lua \
                e2tool.lua e2scm.lua git.lua svn.lua cvs.lua files.lua \
                hash.lua \
                lock.lua \
-               e2build.lua luafile.lua \
+               e2build.lua \
                policy.lua
        $(LUAC) -o $@ $^