mirror of
https://github.com/vicious-widgets/vicious
synced 2023-12-14 07:13:07 +01:00
helpers: simplify pathtotable, patch by filmor
This commit is contained in:
parent
26c1f078d9
commit
76942d17a4
1 changed files with 13 additions and 8 deletions
21
helpers.lua
21
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
|
||||
|
|
Loading…
Reference in a new issue