From 990beef9d0fca7c93fe053a9550bcce39122ada2 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 22 May 2016 23:34:59 -0400 Subject: [PATCH] util: Add a class deprecation function. --- lib/awful/util.lua | 30 ++++++++++++++++++++++++++++++ lib/awful/wibox.lua | 21 +-------------------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/lib/awful/util.lua b/lib/awful/util.lua index 866f9e4f..488dbacf 100644 --- a/lib/awful/util.lua +++ b/lib/awful/util.lua @@ -60,6 +60,36 @@ function util.deprecate(see) gears_debug.print_warning(msg .. ".\n" .. tb) end +--- Create a class proxy with deprecation messages. +-- This is useful when a class has moved somewhere else. +-- @tparam table fallback The new class +-- @tparam string old_name The old class name +-- @tparam string new_name The new class name +-- @treturn table A proxy class. +function util.deprecate_class(fallback, old_name, new_name) + local message = old_name.." has been renamed to "..new_name + + local function call(_,...) + util.deprecate(message) + + return fallback(...) + end + + local function index(_, k) + util.deprecate(message) + + return fallback[k] + end + + local function newindex(_, k, v) + util.deprecate(message) + + fallback[k] = v + end + + return setmetatable({}, {__call = call, __index = index, __newindex = newindex}) +end + --- Get a valid color for Pango markup -- @param color The color. -- @tparam string fallback The color to return if the first is invalid. (default: black) diff --git a/lib/awful/wibox.lua b/lib/awful/wibox.lua index 276b9f38..f56b38f5 100644 --- a/lib/awful/wibox.lua +++ b/lib/awful/wibox.lua @@ -7,26 +7,7 @@ -- @module awful.wibox --------------------------------------------------------------------------- local util = require("awful.util") -local wibar = require("awful.wibar") -local function call(_,...) - util.deprecate("awful.wibox has been renamed to awful.wibar") - - return wibar(...) -end - -local function index(_, k) - util.deprecate("awful.wibox has been renamed to awful.wibar") - - return wibar[k] -end - -local function newindex(_, k, v) - util.deprecate("awful.wibox has been renamed to awful.wibar") - - wibar[k] = v -end - -return setmetatable({}, {__call = call, __index = index, __newindex = newindex}) +return util.deprecate_class(require("awful.wibar"), "awful.wibox", "awful.wibar") -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80