Currently some plugins had/have issues with predicates that check if active view is a docview to perform certain operations like draw in the case of minimap or lineguide. Since is() was checking the entire inheritance tree it was returning true for views that inherit from the same parent, which caused CommandView to be matched along DocView, etc... This change does the following to solve the issue: * Make Object:is() only match the top level parent of the object which is more in line with what one would expect from a method named 'is'. * Introduces Object:extends() which keeps the same functionality that Object:is() offered before.
56 lines
725 B
Lua
56 lines
725 B
Lua
local Object = {}
|
|
Object.__index = Object
|
|
|
|
|
|
function Object:new()
|
|
end
|
|
|
|
|
|
function Object:extend()
|
|
local cls = {}
|
|
for k, v in pairs(self) do
|
|
if k:find("__") == 1 then
|
|
cls[k] = v
|
|
end
|
|
end
|
|
cls.__index = cls
|
|
cls.super = self
|
|
setmetatable(cls, self)
|
|
return cls
|
|
end
|
|
|
|
|
|
function Object:is(T)
|
|
if getmetatable(self) == T then
|
|
return true
|
|
end
|
|
return false
|
|
end
|
|
|
|
|
|
function Object:extends(T)
|
|
local mt = getmetatable(self)
|
|
while mt do
|
|
if mt == T then
|
|
return true
|
|
end
|
|
mt = getmetatable(mt)
|
|
end
|
|
return false
|
|
end
|
|
|
|
|
|
function Object:__tostring()
|
|
return "Object"
|
|
end
|
|
|
|
|
|
function Object:__call(...)
|
|
local obj = setmetatable({}, self)
|
|
obj:new(...)
|
|
return obj
|
|
end
|
|
|
|
|
|
return Object
|