From fd0a433f59ddcd6c6d1f8de83db2da1079b93868 Mon Sep 17 00:00:00 2001 From: jgmdev Date: Thu, 12 May 2022 20:33:01 -0400 Subject: [PATCH] object: made is() stricter and added extends() 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. --- data/core/object.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/data/core/object.lua b/data/core/object.lua index 0941ce5d..a57ac9e8 100644 --- a/data/core/object.lua +++ b/data/core/object.lua @@ -21,6 +21,14 @@ 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