From a5a6a295e07fd47d6f59d663cde38371dd878d89 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sat, 8 Sep 2018 20:55:02 +0200 Subject: common: add simple status code table --- common.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/common.lua b/common.lua index 89153d8..d7d3640 100644 --- a/common.lua +++ b/common.lua @@ -6,6 +6,30 @@ local stringformat = string.format local verboselvl = 0 local colorize = false +local table_mirrored = function (t, only) + local ret = { } + + if t ~= nil then + for k, v in next, t do + ret [k] = v + if only == false then + ret [v] = k + end + end + end + + return ret +end + +local status do + local codes = + { ok = 0 + , error = -1 + } + + status = { codes = table_mirrored (codes) } +end + --- check if stderr is pipe; use color otherwise local ok, unistd = pcall (require, "posix.unistd") if ok then @@ -102,5 +126,6 @@ return , trim_whitespace = trim_whitespace , unescape_string = unescape_string , internalize_value = internalize_value + , status = status } -- cgit v1.2.3