2017-08-14 12:48:36 +00:00
|
|
|
local Class
|
2017-08-14 13:02:36 +00:00
|
|
|
Class = function(name, parent)
|
2017-08-14 12:48:36 +00:00
|
|
|
local newClass, base
|
|
|
|
base = {
|
|
|
|
__index = base,
|
|
|
|
__class = newClass
|
|
|
|
}
|
|
|
|
newClass = setmetable({
|
|
|
|
__init = function() end,
|
|
|
|
__base = base,
|
|
|
|
__name = name
|
|
|
|
}, {
|
|
|
|
__call = function(cls, ...)
|
|
|
|
local self = setmetable({ }, base)
|
|
|
|
cls.__init(self, ...)
|
|
|
|
return self
|
|
|
|
end
|
|
|
|
})
|
2017-08-14 13:02:36 +00:00
|
|
|
if parent then
|
|
|
|
setmetable(base, {
|
|
|
|
__parent = parent.__base
|
|
|
|
})
|
|
|
|
newClass.__parent = parent
|
|
|
|
newClass.__index = function(cls, name)
|
|
|
|
local val = rawget(base, name)
|
|
|
|
if val == nil then
|
|
|
|
return parent[name]
|
|
|
|
else
|
|
|
|
return val
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if parent.__inherited then
|
|
|
|
parent:__inherited(newClass)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return newClass, base
|
2017-08-14 12:48:36 +00:00
|
|
|
end
|
|
|
|
return Class
|