From 92d7dbca9ac95625882cfe8cc6558b198476c6c7 Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Wed, 26 Jun 2019 16:55:16 +0200 Subject: [PATCH] err: add tostring() support and allocate metatable only once Signed-off-by: Tobias Ulmer --- generic/err.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/generic/err.lua b/generic/err.lua index 3170995..82c524f 100644 --- a/generic/err.lua +++ b/generic/err.lua @@ -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 -- 2.39.5