请选择 进入手机版 | 继续访问电脑版
  • 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

lua class

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

 

 

 1 _class = {}
 2 
 3 function BaseClass(super)
 4     local class_type = {}
 5     local vtbl = {}
 6     _class[class_type] = vtbl
 7 
 8     setmetatable(class_type, {
 9         __newindex = function(t, k, v)
10             vtbl[k] = v
11         end,
12         __index = vtbl
13     })
14     if super then
15         setmetatable(vtbl, {
16             __index = _class[super]
17         })
18     end
19 
20 
21     class_type.__init = false
22     class_type.__delete = false
23     class_type.super = super
24     class_type.New = function(...)
25         local obj = {}
26         obj._class_type = class_type
27         setmetatable(obj, {__index = _class[class_type]})
28 
29         do
30             local create = function(c, ...)
31                 if c.super then
32                     create(c.super, ...)
33                 end
34                 if c.__init then
35                     c.__init(obj, ...)
36                 end
37             end
38 
39             create(class_type, ...)
40         end
41 
42         obj.DeleteMe = function(self)
43             local now_super = self._class_type
44             while now_super ~= nil  do
45                 if now_super.__delete then
46                     now_super.__delete(self)
47                 end
48                 now_super = now_super.super
49             end
50         end
51 
52         return obj
53     end
54 
55     return class_type
56 end

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
lua元表发布时间:2022-07-22
下一篇:
本地资源检测支持Lua检测!发布时间:2022-07-22
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap