aboutsummaryrefslogtreecommitdiff
path: root/helpers.lua
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2009-11-11 02:43:11 +0100
committerAdrian C. (anrxc) <anrxc@sysphere.org>2009-11-11 02:43:11 +0100
commit46d52face802ee3b29f1b85455e59fb19442eada (patch)
tree27df313795707de6b9399d5320cba18c0de0098e /helpers.lua
parenteb661f6e1730a41c0c8426f9682057749d372ad5 (diff)
downloadvicious-legacy-46d52face802ee3b29f1b85455e59fb19442eada.tar.xz
helpers: import pathtotable
This helper exposes paths as Lua tables. It will help simplify a lot of widgets. Thanks to Benedikt Sauer for the original idea.
Diffstat (limited to 'helpers.lua')
-rw-r--r--helpers.lua13
1 files changed, 13 insertions, 0 deletions
diff --git a/helpers.lua b/helpers.lua
index 7281080..40070bf 100644
--- a/helpers.lua
+++ b/helpers.lua
@@ -2,11 +2,13 @@
-- Licensed under the GNU General Public License v2
-- * (c) 2009, Adrian C. <anrxc@sysphere.org>
-- * (c) 2009, Rémy C. <shikamaru@mandriva.org>
+-- * (c) 2009, Benedikt Sauer <filmor@gmail.com>
-- * (c) 2008, Lucas de Vries <lucas@glacicle.com>
---------------------------------------------------
-- {{{ Grab environment
local pairs = pairs
+local io = { open = io.open }
local string = {
sub = string.sub,
gsub = string.gsub
@@ -23,6 +25,17 @@ local scroller = {}
-- }}}
-- {{{ Helper functions
+-- {{{ Expose path as a Lua table
+pathtotable = { __index = function (table, name)
+ local f = io.open(table._path .. '/' .. name)
+ if f then
+ local s = f:read("*all")
+ f:close()
+ return s
+ end
+end }
+-- }}}
+
-- {{{ Format a string with args
function format(format, args)
for var, val in pairs(args) do