aboutsummaryrefslogtreecommitdiff
path: root/helpers.lua
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2010-03-15 03:02:50 +0100
committerAdrian C. (anrxc) <anrxc@sysphere.org>2010-03-15 03:02:50 +0100
commit49b1b0972f7db6ef77b459e3010c3b569fa69534 (patch)
tree14205aa46f1ae3c889b9665a9333721576b92bbc /helpers.lua
parent7cbf987a2a22d69de6a5194bb7d8c685f8d6b62e (diff)
downloadvicious-legacy-49b1b0972f7db6ef77b459e3010c3b569fa69534.tar.xz
helpers: index subdirectories in pathtotable()
Diffstat (limited to 'helpers.lua')
-rw-r--r--helpers.lua18
1 files changed, 13 insertions, 5 deletions
diff --git a/helpers.lua b/helpers.lua
index 8b6541d..c61468e 100644
--- a/helpers.lua
+++ b/helpers.lua
@@ -11,6 +11,7 @@
local pairs = pairs
local io = { open = io.open }
local setmetatable = setmetatable
+local getmetatable = getmetatable
local string = {
upper = string.upper,
format = string.format
@@ -28,14 +29,21 @@ local scroller = {}
-- {{{ Helper functions
-- {{{ Expose path as a Lua table
-function pathtotable(path)
- return setmetatable({},
- { __index = function(_, name)
- local f = io.open(path .. '/' .. name)
+function pathtotable(dir)
+ return setmetatable({ _path = dir },
+ { __index = function(table, index)
+ local path = table._path .. '/' .. index
+ local f = io.open(path)
if f then
local s = f:read("*all")
f:close()
- return s
+ if s then
+ return s
+ else
+ local o = { _path = path }
+ setmetatable(o, getmetatable(table))
+ return o
+ end
end
end
})