I have found a new OO style, it is very convenient, so share it for u, any suggestion is welcome.
Client = {
__debug = false, -- 是否调试模式
__online = false, -- 是否联机在线
__timeout = 5000, -- 默认超时时间
}
function Client:New()
object = {}
-- 对象方法继承
setmetatable(object, self)
self.__index = self
-- 对象属性继承
object.__debug = self.__debug
object.__online = self.__online
object.__timeout = self.__timeout
return object
end
function Client:Delete()
-- release resources
end
function Client:Print(...)
print("Client: ", unpack(arg))
end
-- 继承基类对象
CLIENT_XCHAT = Client:New()
function CLIENT_XCHAT:New()
object = {}
-- 对象方法继承
setmetatable(object, self)
self.__index = self
return object
end
function CLIENT_XCHAT:Release()
self:Delete()
end
function CLIENT_XCHAT:Log(...)
self:Print("CLIENT_XCHAT: ", unpack(arg))
end
-- Example
myClient = CLIENT_XCHAT:New()
myClient:Log("Hello world")