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... --- volume.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'volume.lua') diff --git a/volume.lua b/volume.lua index f5b832f..16d4682 100644 --- a/volume.lua +++ b/volume.lua @@ -4,6 +4,7 @@ --------------------------------------------------- -- {{{ Grab environment +local tonumber = tonumber local io = { popen = io.popen } local setmetatable = setmetatable local string = { @@ -24,8 +25,8 @@ local function worker(format, channel) local mixer = f:read("*all") f:close() - local vol = string.match(mixer, "([%d]?[%d]?[%d])%%") - -- If muted return 0 (not "Mute") so we dont break progressbars + local vol = tonumber(string.match(mixer, "([%d]?[%d]?[%d])%%")) + -- If mute return 0 (not "Mute") so we don't break progressbars if string.find(mixer, "%[off%]") or vol == nil then vol = 0 end -- cgit v1.2.3