aboutsummaryrefslogtreecommitdiff
path: root/wifi.lua
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2009-10-26 20:32:48 +0100
committerAdrian C. (anrxc) <anrxc@sysphere.org>2009-10-26 20:32:48 +0100
commit0d73f6d8ae32f1cd48ce9f089b902eb0877605e1 (patch)
tree80d41d5fb6095610c781d47fa1a34e91cf184ce3 /wifi.lua
parentb105ae21cd47682a4e426604cb15ee6c11aea201 (diff)
downloadvicious-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 'wifi.lua')
-rw-r--r--wifi.lua9
1 files changed, 5 insertions, 4 deletions
diff --git a/wifi.lua b/wifi.lua
index 4ef9c00..5e307a0 100644
--- a/wifi.lua
+++ b/wifi.lua
@@ -4,6 +4,7 @@
---------------------------------------------------
-- {{{ Grab environment
+local tonumber = tonumber
local io = { popen = io.popen }
local setmetatable = setmetatable
local string = {
@@ -30,7 +31,7 @@ local function worker(format, iface)
["{mode}"] = "N/A",
["{chan}"] = "N/A",
["{rate}"] = "N/A",
- ["{link}"] = "N/A",
+ ["{link}"] = 0,
["{sign}"] = "N/A"
}
@@ -47,13 +48,13 @@ local function worker(format, iface)
winfo["{mode}"] = -- Modes are simple, but also match the "-" in Ad-Hoc
string.match(iw, "Mode[=:]([%w%-]*)") or winfo["{mode}"]
winfo["{chan}"] = -- Channels are plain digits
- string.match(iw, "Channel[=:]([%d]+)") or winfo["{chan}"]
+ tonumber(string.match(iw, "Channel[=:]([%d]+)") or winfo["{chan}"])
winfo["{rate}"] = -- Bitrate can start with a space and we want to display Mb/s
string.match(iw, "Bit Rate[=:]([%s]?[%d%.]*[%s][%/%a]+)") or winfo["{rate}"]
-- winfo["{link}"] = -- Link quality can contain a slash: 32/100
-- string.match(iw, "Link Quality[=:]([%d]+[%/%d]*)") or winfo["{link}"]
- winfo["{link}"] = -- * match only the first number, great data for a progressbar
- string.match(iw, "Link Quality[=:]([%d]+)") or winfo["{link}"]
+ winfo["{link}"] = -- * match only the first number, also suitable for a progressbar
+ tonumber(string.match(iw, "Link Quality[=:]([%d]+)") or winfo["{link}"])
winfo["{sign}"] = -- Signal level can be a negative value, also display decibel notation
string.match(iw, "Signal level[=:]([%-%d]+[%s][%a]*)") or winfo["{sign}"]