]> git.e2factory.org Git - e2factory.git/commitdiff
err: add tostring() support and allocate metatable only once
authorTobias Ulmer <tu@emlix.com>
Wed, 26 Jun 2019 14:55:16 +0000 (16:55 +0200)
committerTobias Ulmer <tu@emlix.com>
Wed, 26 Jun 2019 14:55:16 +0000 (16:55 +0200)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/err.lua

index 3170995d10756199104a02f87cb4a5ac0f574787..82c524ffd71ade1cf85f9061c9789a5e94f22c97 100644 (file)
@@ -202,6 +202,11 @@ function err.ecdata(e)
     return _errcodes[e.code]
 end
 
+local err_mt = {
+    __index = err,
+    __tostring = err.tostring
+}
+
 --- create an error object
 -- @param format string: format string
 -- @param ... list of arguments required for the format string
@@ -212,8 +217,7 @@ function err.new(format, ...)
     e.count = 0
     e.msg = {}
     e.code = false
-    local meta = { __index = err }
-    setmetatable(e, meta)
+    setmetatable(e, err_mt)
     if format then
         e:append(format, ...)
     end