function class(super, autoConstructSuper)
local classType = {};
classType.autoConstructSuper = autoConstructSuper or (autoConstructSuper == nil); if super then
classType.super = super;
local mt = getmetatable(super);
setmetatable(classType, { __index = super; __newindex = mt and mt.__newindex;});
else
classType.setDelegate = function(self,delegate)
self.m_delegate = delegate;
end
end return classType;
end function new(classType, ...)
local obj = {};
local mt = getmetatable(classType);
setmetatable(obj, { __index = classType; __newindex = mt and mt.__newindex;});
do
local create;
create =
function(c, ...)
if c.super and c.autoConstructSuper then
create(c.super, ...);
end
if rawget(c,"ctor") then
obj.currentSuper = c.super;
c.ctor(obj, ...);
end
end create(classType, ...);
end
obj.currentSuper = nil;
return obj;
end function delete(obj)
do
local destory =
function(c)
while c do
if rawget(c,"dtor") then
c.dtor(obj);
end c = getmetatable(c);
c = c and c.__index;
end
end
destory(obj);
end
end

lua如何构造类的更多相关文章

  1. Sql语句构造类,多字段新增或修改时,拼装sql语句比较方便

    using System; using System.Collections.Generic; using System.Text; namespace MSCL { #region 使用示例 /* ...

  2. 【转载】Lua中实现类的原理

    原文地址 http://wuzhiwei.net/lua_make_class/ 不错,将metatable讲的很透彻,我终于懂了. --------------------------------- ...

  3. quick-cocos2d-x 创建自定义lua绑定c++类

    内容主要参考 “在quick-cocos2d-x中添加自定义的类给lua使用” ( http://www.codeo4.cn/archives/746) 1. quick-coco2d-x 使用 to ...

  4. Python动态构造类:借助强悍的内建 type()

    内建的 type() 函数带三个参数时, 将作为强悍的动态类构造器. 如下: type(name, bases, dict) 返回一个新的type对象. 基本上是 class 语句的动态形式. 参数: ...

  5. 关于Java构造类与对象的思考

    简单记录一下Java构造类与对象时的流程以及this和super对于特殊例子的分析. 首先,接着昨天的问题,我做出了几个变形: Pic1.原版: Pic2.去掉了T.foo方法中的this关键字: P ...

  6. lua 基础 2 类型和值

    -- 类型 和 值--[[ 8中类型 滚动类nil.boolean. number.string.userdata.function.thread 和 table.]] print (type(&qu ...

  7. lua中基类和“继承机制”

    基类:基类定义了所有对于派生类来说普通的属性和方法,派生类从基类继承所需的属性和方法,且在派生类中增加新的属性和方法. 继承:继承是C++语言的一种重要机制,它允许在已定义的类的基础上产生新类. lu ...

  8. lua 面向对象编程类机制实现

    lua no class It is a prototype based language. 在此语言中没有class关键字来创建类. 现代ES6, 已经添加class类. prototype bas ...

  9. cocos2dx lua调用C++类.

    最近需求所迫, 终于着手传说中的 lua 了. 折腾了4天, 总算大概搞明白了用法. 细节咱们就别谈了, 直接说项目里怎么跑起来. 准备工作 我们需要一系列繁琐的前奏. tolua++: 这是必备工具 ...

随机推荐

  1. <<UML大战需求分析>>阅读笔记(2)

    <<UML大战需求分析>>阅读笔记(2)> 此次读了uml大战需求分析的第三四章,我发现这本书讲的特别的好,由于这学期正在学习设计模式这本书,这本书就讲究对uml图的利用 ...

  2. c++:string函数

    string类的构造函数:string(const char *s);    //用c字符串s初始化string(int n,char c);     //用n个字符c初始化此外,string类还支持 ...

  3. 清除路由器NAT地址转换

    首先当你的NAT网络地址转换成功搭建起来,并且测试过网络通信时,此时NAT地址转换表上面是存在转换信息的,你可以通过在特权模式下输入命令"show ip nat translation&qu ...

  4. Win7 64位 VS2015环境使用SDL2-2.0.4

    之前在VS中使用SDL2,如果只链接SDL2.lib,会提示 error LNK2019: unresolved external symbol _main referenced in functio ...

  5. Activity设置全屏的三种方法

    1.super.onCreate(savedInstanceState)方法之前调用:            setTheme(android.R.style.Theme_Light_NoTitleB ...

  6. PYTHON学习之路_PYTHON基础(10)

    学习内容: Python进程与线程 1.线程及线程类 2.线程守护 3.线程等待 4.线程锁 5.信号量 6.timer用法 7.队列 8.事件驱动 9.生产者消费者模型 10.进程及进程同步 11. ...

  7. [转] How to import a large data set using XPO efficiently within a transaction

    https://www.devexpress.com/Support/Center/Example/Details/T333879

  8. NSDate

    NSDate : NSDate *date = [NSDate date];获取当前日期 NSDate 可以进行比较,通过earlierDate:方法获取二个日期中最早的. NSDate 通过late ...

  9. 解决Win7下VC6.0插入ActiveX控件对话框为空的问题

    在Win7环境下,编写MFC应用程序,Project菜单下Add To Project子菜单中的 Components and Controls…选项,在弹出的对话框中Gallery文件为空,也就无法 ...

  10. requirejs按需加载angularjs文件

    之前分享了一篇用ocLazyLoad实现按需加载angular js文件的博客.本来当时想会使用一种方法就行了.可最近刚好有时间,在网上查找了一下requirejs实现angular js文件按需加载 ...