From 35a4b4edbfaabf8b13fbe87b1088f353ec0c3144 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sat, 26 Oct 2019 17:17:48 -0400 Subject: [PATCH] object: Allow old `gears.table.join` accessors to be set to `false`. This worked before, so it has to work again. Fixes #2915 --- lib/gears/object/properties.lua | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/gears/object/properties.lua b/lib/gears/object/properties.lua index e58f18c7..aaf6a961 100644 --- a/lib/gears/object/properties.lua +++ b/lib/gears/object/properties.lua @@ -176,7 +176,25 @@ function object._legacy_accessors(obj, name, capi_name, is_object, join_if, set_ if not is_object then objs, self = self, obj end - assert(objs) + + -- When using lua expressions like `false and true and my_objects`, + -- it is possible the code ends up as a boolean rather than `nil` + -- the resulting type is sometime counter intuitive and different + -- from similar languages such as JavaScript. Be forgiving and correct + -- course. + if objs == false then + objs = nil + end + + -- Sometime, setting `nil` might be volontary since the user might + -- expect it will act as "clear". The correct thing would be to set + -- `{}`, but allow it nevertheless. + + if objs == nil then + objs = {} + end + + assert(self) -- When called from a declarative property list, "buttons" will be set -- using the result of gears.table.join, detect this