diff --git a/classic.lua b/classic.lua index cbd6f81..dfff63a 100644 --- a/classic.lua +++ b/classic.lua @@ -41,7 +41,7 @@ function Object:implement(...) end -function Object:is(T) +function Object:isinstance(T) local mt = getmetatable(self) while mt do if mt == T then @@ -53,6 +53,19 @@ function Object:is(T) end +function Object:issubclass(T) + assert(rawget(self, "super"), "is not a class") + local mt = self + while mt do + if mt == T then + return true + end + mt = getmetatable(mt) + end + return false +end + + function Object:__tostring() return "Object" end