awful.widget.graph: expose properties via getters

This allows to see if a widget is stacked for example.

It uses getters instead of exposing the properties directly, which
should be made readonly then probably (which has drawbacks according to [1]).

1: http://lua-users.org/wiki/ReadOnlyTables

Closes https://github.com/awesomeWM/awesome/pull/284.
This commit is contained in:
Daniel Hahler 2015-07-04 20:10:39 +02:00
parent 611438a892
commit 3be423fcb3
1 changed files with 6 additions and 0 deletions

View File

@ -229,6 +229,11 @@ for _, prop in ipairs(properties) do
return _graph return _graph
end end
end end
if not graph["get_" .. prop] then
graph["get_" .. prop] = function(_graph)
return data[_graph][prop]
end
end
end end
--- Create a graph widget. --- Create a graph widget.
@ -254,6 +259,7 @@ function graph.new(args)
for _, prop in ipairs(properties) do for _, prop in ipairs(properties) do
_graph["set_" .. prop] = graph["set_" .. prop] _graph["set_" .. prop] = graph["set_" .. prop]
_graph["get_" .. prop] = graph["get_" .. prop]
end end
return _graph return _graph