util: Add a class deprecation function.

This commit is contained in:
Emmanuel Lepage Vallee 2016-05-22 23:34:59 -04:00
parent 3f0d218f72
commit 990beef9d0
2 changed files with 31 additions and 20 deletions

View File

@ -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)

View File

@ -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