Skip to content

Commit

Permalink
only call layouts that are callable in uzful.layout.build
Browse files Browse the repository at this point in the history
  • Loading branch information
dodo committed Apr 18, 2015
1 parent 9ae4879 commit abbcd77
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 5 additions & 5 deletions layout/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
local util = {}

local tag = require("awful.tag")
local uzful = { util = require("uzful.util") }


--- Builds a layout from a table tree
Expand All @@ -16,17 +17,16 @@ local tag = require("awful.tag")
-- @param tree the table describing the layout (can be recursive)
-- @return a layout or the result of the given function or just the input
function util.build(tree)
if not tree then return end
if type(tree) == "function" then
return tree()
end
if tree.layout then
if uzful.util.iscallable(tree.layout) then
local value = nil
local layout = tree.layout()
for i=1,#tree do
if tree[i] then
value = util.build(tree[i])
if value then layout:add(value) end
end
value = util.build(tree[i])
if value then layout:add(value) end
end
for key, value in pairs(tree) do
if type(key) == "string" and layout["set_" .. key] then
Expand Down
8 changes: 8 additions & 0 deletions util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -312,5 +312,13 @@ function util.lineswrap(s, n)
return table.concat(lines, "\n")
end

function util.iscallable(object)
if not object then return false end
if type(object) == 'function' then return true end
local metatable = getmetatable(object)
if metatable and metatable.__call then return true end
return false
end


return util

0 comments on commit abbcd77

Please sign in to comment.