diff options
author | Philipp Gesang <phg@phi-gamma.net> | 2018-09-08 20:55:02 +0200 |
---|---|---|
committer | Philipp Gesang <phg@phi-gamma.net> | 2018-09-08 20:55:02 +0200 |
commit | a5a6a295e07fd47d6f59d663cde38371dd878d89 (patch) | |
tree | 40c157ab11f2bc0eed756772b68e730ed6accce7 | |
parent | 318e8a990ebe94c48f69d3bb1d342a31cf55f1db (diff) | |
download | caldr-a5a6a295e07fd47d6f59d663cde38371dd878d89.tar.gz |
common: add simple status code table
-rw-r--r-- | common.lua | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -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 } |