From c96487515f90b7d0e785e1b672c5b3281275995f Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 20 Oct 2019 01:10:08 -0400 Subject: [PATCH] object: Make the legacy accessor code more robust. * Using `= one and two or three` is a bad idea on boolean. * Using # to check if a table has content doesn't work on named keys --- lib/gears/object/properties.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/gears/object/properties.lua b/lib/gears/object/properties.lua index 6118ef4c3..d1ab5a223 100644 --- a/lib/gears/object/properties.lua +++ b/lib/gears/object/properties.lua @@ -135,7 +135,7 @@ end -- -- TO BE USED FOR DEPRECATION ONLY. -local function copy_object(obj, to_set, name, capi_name, is_object, join_if, set_empty) +local function copy_object(obj, to_set, name, capi_name, is_object, join_if, set_empty)-- luacheck: no unused local ret = gtable.clone(to_set, false) -- .buttons used to be a function taking the result of `gears.table.join`. @@ -148,12 +148,14 @@ local function copy_object(obj, to_set, name, capi_name, is_object, join_if, set -- {deprecated_in=5} -- ) - new_objs, self = is_object and new_objs or self, is_object and self or obj + if not is_object then + new_objs, self = self, obj + end + + local has_content = new_objs and next(new_objs) -- Setter - if new_objs and #new_objs > 0 then - if (not set_empty) and not next(new_objs) then return end - + if new_objs and has_content then local is_formatted = join_if(new_objs) -- Because modules may rely on :buttons taking a list of