From 7d0f4ca327e416ebb1c4baf05a8aff8f8cbc2524 Mon Sep 17 00:00:00 2001 From: Gordon Hecker Date: Thu, 21 Jan 2010 15:18:47 +0100 Subject: [PATCH] cleanup: turn luafile into a proper lua module Signed-off-by: Gordon Hecker --- generic/loader.lua | 1 + generic/luafile.lua | 52 ++++++++++++++++++++------------------------- local/Makefile | 14 ++++++------ 3 files changed, 31 insertions(+), 36 deletions(-) diff --git a/generic/loader.lua b/generic/loader.lua index dfc04b7..cd1ad75 100644 --- a/generic/loader.lua +++ b/generic/loader.lua @@ -31,3 +31,4 @@ require("e2util") require("luafile_ll") require("e2option") +require("luafile") diff --git a/generic/luafile.lua b/generic/luafile.lua index fcddb68..cc0f63b 100644 --- a/generic/luafile.lua +++ b/generic/luafile.lua @@ -25,24 +25,18 @@ along with this program. If not, see . ]] -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 diff --git a/local/Makefile b/local/Makefile index 81bb73f..79cfce2 100644 --- a/local/Makefile +++ b/local/Makefile @@ -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 $@ $^ -- 2.39.5