add proto_isa()
authorChristian Thaeter <ct@pipapo.org>
Wed, 5 Nov 2014 22:44:26 +0000 (23:44 +0100)
committerChristian Thaeter <ct@pipapo.org>
Wed, 5 Nov 2014 22:44:26 +0000 (23:44 +0100)
proto.lua

index 342f5b0..b2fca52 100644 (file)
--- a/proto.lua
+++ b/proto.lua
@@ -176,6 +176,23 @@ function Object:proto_objectof(name)
 end
 
 
+--- Object:proto_isa (prototype)
+---   check if self is inherited from prototype
+function Object:proto_isa(prototype)
+    if self == prototype then
+        return true
+    else
+        local parents = rawget(self, "__proto_parents") or {self.__index} or {}
+        for i=1,#parents do
+            if parents[i]:proto_isa(prototype) then
+                return true
+            end
+        end
+    end
+    return false
+end
+
+
 return Object
 
 -- Local Variables: