diff options
author | Adrian C. (anrxc) <anrxc@sysphere.org> | 2009-10-26 20:32:48 +0100 |
---|---|---|
committer | Adrian C. (anrxc) <anrxc@sysphere.org> | 2009-10-26 20:32:48 +0100 |
commit | 0d73f6d8ae32f1cd48ce9f089b902eb0877605e1 (patch) | |
tree | 80d41d5fb6095610c781d47fa1a34e91cf184ce3 /batat.lua | |
parent | b105ae21cd47682a4e426604cb15ee6c11aea201 (diff) | |
download | vicious-legacy-0d73f6d8ae32f1cd48ce9f089b902eb0877605e1.tar.xz |
Ensure returned numbers are of type number
Thanks to Felix for bringing this to my attention. Obviously there was
already a safety net for feeding progressbars and graphs... and while
this makes for a good coding practice it's not a big deal. We have
widgets of type textbox for one, and a lot of string concatenation
happens. Strings are formatted, markup is applied...
Diffstat (limited to 'batat.lua')
-rw-r--r-- | batat.lua | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -4,6 +4,7 @@ --------------------------------------------------- -- {{{ Grab environment +local tonumber = tonumber local io = { popen = io.popen } local setmetatable = setmetatable local table = { insert = table.insert } @@ -34,11 +35,11 @@ local function worker(format) if string.match(line, "^[%s]+Battery.*") then -- Store state and charge information table.insert(battery_info, (battery_state[string.match(line, "([%a]*),") or "unknown"])) - table.insert(battery_info, (string.match(line, "([%d]?[%d]?[%d])%.") or "0")) + table.insert(battery_info, (tonumber(string.match(line, "([%d]?[%d]?[%d])%.")) or 0)) -- Store remaining time information table.insert(battery_info, (string.match(line, "%%,%s(.*)") or "N/A")) else - return {battery_state["unknown"], "0", "N/A"} + return {battery_state["unknown"], 0, "N/A"} end end f:close() |