summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2018-09-08 20:55:02 +0200
committerPhilipp Gesang <phg@phi-gamma.net>2018-09-08 20:55:02 +0200
commita5a6a295e07fd47d6f59d663cde38371dd878d89 (patch)
tree40c157ab11f2bc0eed756772b68e730ed6accce7
parent318e8a990ebe94c48f69d3bb1d342a31cf55f1db (diff)
downloadcaldr-a5a6a295e07fd47d6f59d663cde38371dd878d89.tar.gz
common: add simple status code table
-rw-r--r--common.lua25
1 files changed, 25 insertions, 0 deletions
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
}