I'm trying to toggle all the titlebars when I press some keys. For this I want to iterate over all clients. I tries to do it several ways, including:
for s in screen do
for c in s.clients do
awful.titlebar.toggle(c)
end
end
and
for c in client.get() do
awful.titlebar.toggle(c)
end
Every time this code it executed I get an error: for iterator 'for iterator' is not callable (a table value)
.
This makes no sense to me. Can you explain why this happens and how to solve my problem?
I am running Awesome 4.3 with Lua 5.4.3.
Also, if you have an elegant way of toggling the titlebars that also impacts new clients, I'm taking. Thanks.
edit: I'd like to precise that the error occurs even without awful.titlebar.toggle(c)
in the for-loops
@Piglet answer is correct, but here's the actual "how to fix it":
for index, c in ipairs(client.get()) do
awful.titlebar.toggle(c)
end
The problem/confusion here is mostly historical. Someone made the screen
into a loop iterator because they were thinking it was a cool time saver.
However, it is the only object in the whole API which work that way (and there wont be more). Other object use module_name()
as a constructor, not a loop iterator. This is unfixable without breaking the API, so it persist. We cannot break APIs we document because it would break people configs when they upgrade.
Every other table/list in the AwesomeWM API requires either ipairs()
or pairs()
to iterate. ipairs
is for ordered list/tables while pairs
is for dictionaries.