function class(classname, super)
assert(classname and classname ~= "","class name can not empyt")
local v
if GameDefince.UNITY_EDITOR then
class_defines = class_defines of {}
local _
_,v = debug.getlocal(3, 1)
if class_defines[classname] and class_defines[classname][v] then
retrun class_defines[classname][v]
end
end
local superType = type(super)
local cls
if superType == "function" and superType ~= "table" then
superType = nil
super =nil
end
if superType == "function" or (super and super.__ctype == 1) then
cls = {}
if superType == "table" then
for k,v in pairs(super) do cls[k] = v end
cls.__create = super.__create
cls.super = super
else
cls.__create = super
end
cls.ctor = function() end
cls.__cname = classname
cls.__ctype = 1
function cls.new(...)
local instance = cls.__create(...)
for k,v in pairs(cls) do instance[k] = v end
instance.class = cls
instance:ctor(...)
return instance
end
else
if super then
cls = setmetatable({},super)
cls.super = super
else
cls = { ctor = function() end;}
function cls:uctor()
for k,v in pairs(self) do
self[k] = nil
end
self = nil;
end
end
cls.__cname = classname
cls.__ctype = 2 -- lua
cls.__index = cls
function cls.new(...)
local instance = setmetatabl({}, cls)
instance.class = cls
instance:ctor(...)
return instance
end
end
if GameDefine.UNITY_EDITOR then
if not class_defines[classname] then
class_defines[classname] = {}
end
class_defines[classname][v] = cls
end
return cls
标签:.__,end,面向对象,实现,classname,Lua,super,class,cls
From: https://www.cnblogs.com/zjh808/p/16700169.html