]> git.e2factory.org Git - e2factory.git/commitdiff
cleanup: rename error module to err and turn into proper lua module
authorGordon Hecker <gh@emlix.com>
Thu, 21 Jan 2010 14:36:13 +0000 (15:36 +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/err.lua [moved from generic/error.lua with 89% similarity]
generic/loader.lua
local/Makefile

similarity index 89%
rename from generic/error.lua
rename to generic/err.lua
index a71e9068680f2ffeaedbb47e99ac75b5c32a58e2..e1925439873ecff2dbe2ed1c1311b2afd4c47516 100644 (file)
@@ -4,34 +4,35 @@
    Copyright (C) 2007-2009 Gordon Hecker <gh@emlix.com>, emlix GmbH
    Copyright (C) 2007-2009 Oskar Schirmer <os@emlix.com>, 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 <http://www.gnu.org/licenses/>.
 ]]
 
-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
index 0c723a3b73068b2d5cec3c495e6fb567ded25f74..13bfabcd673c7338b92fb1dbc083403cad41dbe4 100644 (file)
@@ -33,3 +33,4 @@ require("luafile_ll")
 require("e2option")
 require("luafile")
 require("generic_git")
+require("err")
index cb6e87e23ff53e3ff0f475b5a91443be30de4345..b6c46ce50eaa2589b92fae6422f79735340965a5 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 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 \