From: Gordon Hecker Date: Thu, 21 Jan 2010 14:36:13 +0000 (+0100) Subject: cleanup: rename error module to err and turn into proper lua module X-Git-Tag: e2factory-2.3.4pre1~27 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=7b9d21c115a5ab6994d50accdcc9f2cc8af35386;p=e2factory.git cleanup: rename error module to err and turn into proper lua module Signed-off-by: Gordon Hecker --- diff --git a/generic/error.lua b/generic/err.lua similarity index 89% rename from generic/error.lua rename to generic/err.lua index a71e906..e192543 100644 --- a/generic/error.lua +++ b/generic/err.lua @@ -4,34 +4,35 @@ Copyright (C) 2007-2009 Gordon Hecker , emlix GmbH Copyright (C) 2007-2009 Oskar Schirmer , emlix GmbH Copyright (C) 2007-2008 Felix Winkelmann, emlix GmbH - + For more information have a look at http://www.e2factory.org e2factory is a registered trademark by emlix GmbH. This file is part of e2factory, the emlix embedded build system. - + e2factory is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see . ]] -local error = {} + +module("err", package.seeall) --- append a string to an error object -- @param format string: format string -- @param ... list of strings required for the format string -- @return table: the error object -function error.append(e, format, ...) +function append(e, format, ...) e.count = e.count + 1 table.insert(e.msg, string.format(format, ...)) return e @@ -41,7 +42,7 @@ end -- @param e table: the error object -- @param re table: the error object to insert -- @return table: the error object -function error.cat(e, re) +function cat(e, re) -- auto-convert strings to error objects before inserting if type(re) == "string" then re = new_error(re) @@ -51,7 +52,7 @@ function error.cat(e, re) return e end -function error.print(e, depth) +function print(e, depth) if not depth then depth = 1 else @@ -73,14 +74,14 @@ end -- @param e the error object -- @param n number: new error counter setting -- @return nil -function error.setcount(e, n) +function setcount(e, n) e.count = n end --- get the error counter -- @param e the error object -- @return number: the error counter -function error.getcount(e, n) +function getcount(e, n) return e.count end @@ -92,11 +93,8 @@ function new_error(format, ...) local e = {} e.count = 0 e.msg = {} - e.append = error.append - e.cat = error.cat - e.print = error.print - e.setcount = error.setcount - e.getcount = error.getcount + local meta = { __index = err } + setmetatable(e, meta) if format then e:append(format, ...) end @@ -110,3 +108,5 @@ function toerror(x) return new_error(x) end end + +_G.new_error = new_error diff --git a/generic/loader.lua b/generic/loader.lua index 0c723a3..13bfabc 100644 --- a/generic/loader.lua +++ b/generic/loader.lua @@ -33,3 +33,4 @@ require("luafile_ll") require("e2option") require("luafile") require("generic_git") +require("err") diff --git a/local/Makefile b/local/Makefile index cb6e87e..b6c46ce 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 luafile.lua generic_git.lua +LUA_LIBS = e2option.lua luafile.lua generic_git.lua err.lua LOCALTOOLS = $(LOCALSHTOOLS) $(LOCALLUATOOLS) SYMLINKS_2_1 = lookup-server use-source prepare-cargo sync-results cleanup \ @@ -123,7 +123,6 @@ e2local.lc: strict.lua \ tools.lua \ transport.lua \ cache.lua \ - error.lua \ url.lua \ collection.lua \ e2lib.lua \