aboutsummaryrefslogtreecommitdiff
path: root/helpers.lua
diff options
context:
space:
mode:
Diffstat (limited to 'helpers.lua')
-rw-r--r--helpers.lua13
1 files changed, 12 insertions, 1 deletions
diff --git a/helpers.lua b/helpers.lua
index c731ae8..e8d6d6c 100644
--- a/helpers.lua
+++ b/helpers.lua
@@ -12,7 +12,8 @@ local io = { open = io.open }
local setmetatable = setmetatable
local string = {
sub = string.sub,
- gsub = string.gsub
+ gsub = string.gsub,
+ format = string.format
}
-- }}}
@@ -51,6 +52,16 @@ function format(format, args)
end
-- }}}
+-- {{{ Format units to one decimal point
+function uformat(array, key, value, unit)
+ for u, v in pairs(unit) do
+ array["{"..key.."_"..u.."}"] = string.format("%.1f", value/v)
+ end
+
+ return array
+end
+-- }}}
+
-- {{{ Escape a string
function escape(text)
local xml_entities = {