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. 1260: [CQOI2007]涂色paint

    Description 假设你有一条长度为5的木版,初始时没有涂过任何颜色.你希望把它的5个单位长度分别涂上红.绿.蓝.绿.红色,用一个长度为5的字符串表示这个目标:RGBGR. 每次你可以把一段连续 ...

  2. 19. UIAlertController 提示框获取文本内容,打印控制台上

    1.首先定义一个全局字符串变量,方便接收获取的文本内容 2. -(void)viewDidAppear:(BOOL)animated{ UIAlertController * alert = [UIA ...

  3. SAX解析xml文件

    需要做一个银行名字的列表. 因为有很多,所以想到了用xml来保存,然后uongDAX解析. public class BankSelectActivity extends BaseActivity{ ...

  4. enum类型学习笔记

    如:enum color {red,white,yellow,green} 枚举出一种类型中的多个变量 enum本质为int,可以作为int使用: enum默认值为0,1,2... 以上的定义中: e ...

  5. 基于Django的web开发

    github地址:https://github.com/shirleyandgithub/PythonWeb

  6. Discuz!X2大附件上传插件-Xproer.HttpUploader6

    插件代码(github):https://github.com/1269085759/up6-discuz 插件代码(coding):https://coding.net/u/xproer/p/up6 ...

  7. [UE4]CustomAnimationBlueprintNode 自定义动画蓝图节点

    目的:在AnimationBlueprint中使用自定义动画控制节点. 主要过程: 1.      引用相关模块.在Client.Build.cs文件中,PublicDependencyModuleN ...

  8. Activity调用静态方法改变UI,使用Handler来改变UI显示

    本人菜鸟,请各位多多指点,不足之处,请斧正.没啥技术含量,就权当丰富下mono for android的小代码. Activity调用静态方法改变UI using System; using Andr ...

  9. wrHDL编译中软核代码初始化及编译耗时长的问题

    问题的提出整个WR的ISE工程比较大,编译时间很长,导致开发效率低.通过分析发现,ISE在综合的时候大量的时间都花在了初始化DPRAM上.调研发现Xilinx提供了BMM文件和DATA2MEM工具,可 ...

  10. JavaScript对异常的处理

    JavaScript提供了一套异常处理机制.当查出事故时,你的程序应该抛出一个异常: var add=function(a,b){ if(typeof a !== 'number' || typeof ...