From 0d73f6d8ae32f1cd48ce9f089b902eb0877605e1 Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Mon, 26 Oct 2009 20:32:48 +0100 Subject: 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... --- wifi.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'wifi.lua') 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}"] -- cgit v1.2.3