aboutsummaryrefslogtreecommitdiff
path: root/mem.lua
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2010-03-13 02:11:41 +0100
committerAdrian C. (anrxc) <anrxc@sysphere.org>2010-03-13 02:11:41 +0100
commit96a8e557d3bb9b887dd7d504a4c20f05a87e6cbe (patch)
treea3f33876efaf5a3473f8aaa72a08368009fc4d2e /mem.lua
parent6441db0a9408a88780494d476f6611a52b41a24d (diff)
downloadvicious-legacy-96a8e557d3bb9b887dd7d504a4c20f05a87e6cbe.tar.xz
Make use of io.lines() where appropriate
Diffstat (limited to 'mem.lua')
-rw-r--r--mem.lua8
1 files changed, 3 insertions, 5 deletions
diff --git a/mem.lua b/mem.lua
index f331ae4..7c18c89 100644
--- a/mem.lua
+++ b/mem.lua
@@ -5,7 +5,7 @@
---------------------------------------------------
-- {{{ Grab environment
-local io = { open = io.open }
+local io = { lines = io.lines }
local setmetatable = setmetatable
local math = { floor = math.floor }
local string = { gmatch = string.gmatch }
@@ -18,11 +18,10 @@ module("vicious.mem")
-- {{{ Memory widget type
local function worker(format)
- -- Get meminfo
- local f = io.open("/proc/meminfo")
local mem = { buf = {}, swp = {} }
- for line in f:lines() do
+ -- Get MEM info
+ for line in io.lines("/proc/meminfo") do
for k, v in string.gmatch(line, "([%a]+):[%s]+([%d]+).+") do
if k == "MemTotal" then mem.total = math.floor(v/1024)
elseif k == "MemFree" then mem.buf.f = math.floor(v/1024)
@@ -33,7 +32,6 @@ local function worker(format)
end
end
end
- f:close()
-- Calculate memory percentage
mem.free = mem.buf.f + mem.buf.b + mem.buf.c