diff options
author | Adrian C. (anrxc) <anrxc@sysphere.org> | 2009-11-11 14:30:26 +0100 |
---|---|---|
committer | Adrian C. (anrxc) <anrxc@sysphere.org> | 2009-11-11 14:30:26 +0100 |
commit | 76942d17a448a2f6a45fb4b3d4d139c416fdf376 (patch) | |
tree | c0e6c79d0884cad6698a0a3004826888e8bc3332 /helpers.lua | |
parent | 26c1f078d943f08b7b53f702bd02cc7537f809e9 (diff) | |
download | vicious-legacy-76942d17a448a2f6a45fb4b3d4d139c416fdf376.tar.xz |
helpers: simplify pathtotable, patch by filmor
Diffstat (limited to 'helpers.lua')
-rw-r--r-- | helpers.lua | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/helpers.lua b/helpers.lua index 40070bf..c5ff15e 100644 --- a/helpers.lua +++ b/helpers.lua @@ -9,6 +9,7 @@ -- {{{ Grab environment local pairs = pairs local io = { open = io.open } +local setmetatable = setmetatable local string = { sub = string.sub, gsub = string.gsub @@ -26,14 +27,18 @@ 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 } +function pathtotable(path) + return setmetatable({}, + { __index = function(_, name) + local f = io.open(path .. '/' .. name) + if f then + local s = f:read("*all") + f:close() + return s + end + end + }) +end -- }}} -- {{{ Format a string with args |