Module:Inheritance

local i = {}

local Class = {} Class.__index = Class;

setmetatable(Class, { __call = function (cls, ...)    local self = setmetatable({}, cls);    self:init(...);    return self;  end, });

function Class:init end

function Class:isa(aClass) local crrClass = self; while nil ~= crrClass do   if crrClass == aClass then return true; end crrClass = crrClass:super; end return false end

function Class:super return nil; end

i.Class = Class;

---

function i.extend(baseClass) -- limit inheritance to module class tree assert(baseClass ~= nil   and baseClass["isa"] ~= nil    and baseClass:isa(Class));

local thisClass = {} thisClass.__index = thisClass; setmetatable(thisClass, {   __index = baseClass,    __call = function (cls, ...)      local self = setmetatable({}, cls)      self:init(...);      return self;    end,  }); function thisClass:super return baseClass; end return thisClass; end

return i;