码迷,mamicode.com
首页 > 其他好文 > 详细

LUA_OBJECT

时间:2020-02-29 17:32:46      阅读:70      评论:0      收藏:0      [点我收藏+]

标签:use   his   mil   The   github   ssi   and   war   ace   

--
-- classic, object model.
--
-- Copyright (c) 2014, rxi
--
-- This module is free software; you can redistribute it and/or modify it under
-- the terms of the MIT license. See LICENSE for details.
--
-- Base object model used with Kong, see [classic github repo](https://github.com/rxi/classic) for usage information

local Object = {}
Object.__index = Object

function Object:new()
end

function Object:extend()
local cls = {}
for k, v in pairs(self) do
if k:find("__") == 1 then
cls[k] = v
end
end
cls.__index = cls
cls.super = self
setmetatable(cls, self)
return cls
end
function Object:implement(...)
for _, cls in pairs({...}) do
for k, v in pairs(cls) do
if self[k] == nil and type(v) == "function" then
self[k] = v
end
end
end
end
function Object:is(T)
local mt = getmetatable(self)
while mt do
if mt == T then
return true
end
mt = getmetatable(mt)
end
return false
end
function Object:__tostring()
return "Object"
end
function Object:__call(...)
local obj = setmetatable({}, self)
obj:new(...)
return obj
end
return Object

LUA_OBJECT

标签:use   his   mil   The   github   ssi   and   war   ace   

原文地址:https://www.cnblogs.com/justart/p/12383886.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!