helpers: simplify pathtotable, patch by filmor
This commit is contained in:
parent
26c1f078d9
commit
76942d17a4
21
helpers.lua
21
helpers.lua
|
@ -9,6 +9,7 @@
|
||||||
-- {{{ Grab environment
|
-- {{{ Grab environment
|
||||||
local pairs = pairs
|
local pairs = pairs
|
||||||
local io = { open = io.open }
|
local io = { open = io.open }
|
||||||
|
local setmetatable = setmetatable
|
||||||
local string = {
|
local string = {
|
||||||
sub = string.sub,
|
sub = string.sub,
|
||||||
gsub = string.gsub
|
gsub = string.gsub
|
||||||
|
@ -26,14 +27,18 @@ local scroller = {}
|
||||||
|
|
||||||
-- {{{ Helper functions
|
-- {{{ Helper functions
|
||||||
-- {{{ Expose path as a Lua table
|
-- {{{ Expose path as a Lua table
|
||||||
pathtotable = { __index = function (table, name)
|
function pathtotable(path)
|
||||||
local f = io.open(table._path .. '/' .. name)
|
return setmetatable({},
|
||||||
if f then
|
{ __index = function(_, name)
|
||||||
local s = f:read("*all")
|
local f = io.open(path .. '/' .. name)
|
||||||
f:close()
|
if f then
|
||||||
return s
|
local s = f:read("*all")
|
||||||
end
|
f:close()
|
||||||
end }
|
return s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
||||||
|
end
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
-- {{{ Format a string with args
|
-- {{{ Format a string with args
|
||||||
|
|
Loading…
Reference in New Issue