--=======================================================
--functions
--=======================================================
---
-- @function [parent = #global] class
-- @param name
-- @param super
-- @return table#table
function class(name, super)
local cls = {}
if super then
for k, v in pairs(super) do cls[k] = v end
cls.super = super
else
cls = { ctor = function() end }
end
cls.__name = name
cls.__index = cls
function cls.new(...)
local instance = setmetatable({}, cls)
instance.class = cls
instance:ctor(...)
return instance
end
return cls
end
---
-- @function[parent=#global] singletonClass
-- @param name
-- @return table#table
function singletonClass(name)
local cls = { ctor = function() end }
cls.__name = name
cls.__index = cls
cls._init = false
function cls.Instance()
if not cls._init then
cls.ctor()
cls._init = true
end
return cls
end
return cls
end
---
-- @function[parent=#global] singletonClass
-- @param name
-- @param super
-- @return table#table
function singletonClass(name, super)
local cls = {}
if super then
for k, v in pairs(super) do cls[k] = v end
cls.super = super
else
cls = { ctor = function() end }
end
cls.__name = name
cls.__index = cls
cls._init = false
function cls.Instance()
if not cls._init then
cls.ctor()
cls._init = true
end
return cls
end
return cls
end
lua类的实现
最新推荐文章于 2020-11-24 20:39:44 发布