Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Class = {Name = "Class", Parents = {}}
- function Class.ClassConstructor(class)
- function class:New(classConstructor, constructor, otherParents)
- local newClass =
- {
- ClassConstructor = function(newClass, ...)
- newClass.Parent = class
- local parents = {class, otherParents}
- newClass.Parents = parents
- for i = 1, #parents do
- parents[i].ClassConstructor(newClass, ...)
- newClass.Ancestors[parents[i]] = true
- end
- classConstructor(newClass, ...)
- newClass.constructor = constructor
- newClass.new = constructor and
- function(...)
- local instance = setmetatable({}, newClass)
- constructor(instance, ...)
- return instance
- end
- or function() return setmetatable({}, newClass) end
- end;
- }
- newClass.ClassConstructor(newClass)
- return newClass
- end
- function class:Is(other)
- return self.Ancestors[other]
- end
- function class:ToTable()
- self.Parent = nil
- return setmetatable(self, nil)
- end
- function class:FromTable(t)
- t.Parent = self
- return setmetatable(t, self)
- end
- class.Ancestors = {}
- class.Class = class
- class.__index = class
- end
- Class.ClassConstructor(Class)
- return Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement