From 96a8e557d3bb9b887dd7d504a4c20f05a87e6cbe Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Sat, 13 Mar 2010 02:11:41 +0100 Subject: Make use of io.lines() where appropriate --- cpu.lua | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'cpu.lua') diff --git a/cpu.lua b/cpu.lua index 9f3839e..7c4907c 100644 --- a/cpu.lua +++ b/cpu.lua @@ -6,7 +6,7 @@ -- {{{ Grab environment local ipairs = ipairs -local io = { open = io.open } +local io = { lines = io.lines } local setmetatable = setmetatable local math = { floor = math.floor } local table = { insert = table.insert } @@ -28,11 +28,10 @@ local cpu_active = {} -- {{{ CPU widget type local function worker(format) - -- Get /proc/stat - local f = io.open("/proc/stat") local cpu_lines = {} - for line in f:lines() do + -- Get CPU stats + for line in io.lines("/proc/stat") do if string.find(line, "^cpu") then cpu_lines[#cpu_lines+1] = {} @@ -41,7 +40,6 @@ local function worker(format) end end end - f:close() -- Ensure tables are initialized correctly while #cpu_total < #cpu_lines do -- cgit v1.2.3