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... --- gmail.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'gmail.lua') diff --git a/gmail.lua b/gmail.lua index 345f6a6..2cdc9b9 100644 --- a/gmail.lua +++ b/gmail.lua @@ -4,6 +4,7 @@ --------------------------------------------------- -- {{{ Grab environment +local tonumber = tonumber local io = { popen = io.popen } local setmetatable = setmetatable local string = { match = string.match } @@ -24,7 +25,7 @@ local function worker(format, feed) local auth = user .. ":" .. pass local feed = feed or "https://mail.google.com/mail/feed/atom/unread" local mail = { - ["{count}"] = "0", + ["{count}"] = 0, ["{subject}"] = "N/A" } @@ -34,7 +35,7 @@ local function worker(format, feed) -- Could be huge don't read it all at once, info we are after is at the top for line in f:lines() do mail["{count}"] = -- Count comes before messages and matches at least 0 - string.match(line, "([%d]+)") or mail["{count}"] + tonumber(string.match(line, "([%d]+)")) or mail["{count}"] -- Find subject tags local title = string.match(line, "(.*)") -- cgit v1.2.3