lua如何构造类
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如何构造类的更多相关文章
- Sql语句构造类,多字段新增或修改时,拼装sql语句比较方便
using System; using System.Collections.Generic; using System.Text; namespace MSCL { #region 使用示例 /* ...
- 【转载】Lua中实现类的原理
原文地址 http://wuzhiwei.net/lua_make_class/ 不错,将metatable讲的很透彻,我终于懂了. --------------------------------- ...
- quick-cocos2d-x 创建自定义lua绑定c++类
内容主要参考 “在quick-cocos2d-x中添加自定义的类给lua使用” ( http://www.codeo4.cn/archives/746) 1. quick-coco2d-x 使用 to ...
- Python动态构造类:借助强悍的内建 type()
内建的 type() 函数带三个参数时, 将作为强悍的动态类构造器. 如下: type(name, bases, dict) 返回一个新的type对象. 基本上是 class 语句的动态形式. 参数: ...
- 关于Java构造类与对象的思考
简单记录一下Java构造类与对象时的流程以及this和super对于特殊例子的分析. 首先,接着昨天的问题,我做出了几个变形: Pic1.原版: Pic2.去掉了T.foo方法中的this关键字: P ...
- lua 基础 2 类型和值
-- 类型 和 值--[[ 8中类型 滚动类nil.boolean. number.string.userdata.function.thread 和 table.]] print (type(&qu ...
- lua中基类和“继承机制”
基类:基类定义了所有对于派生类来说普通的属性和方法,派生类从基类继承所需的属性和方法,且在派生类中增加新的属性和方法. 继承:继承是C++语言的一种重要机制,它允许在已定义的类的基础上产生新类. lu ...
- lua 面向对象编程类机制实现
lua no class It is a prototype based language. 在此语言中没有class关键字来创建类. 现代ES6, 已经添加class类. prototype bas ...
- cocos2dx lua调用C++类.
最近需求所迫, 终于着手传说中的 lua 了. 折腾了4天, 总算大概搞明白了用法. 细节咱们就别谈了, 直接说项目里怎么跑起来. 准备工作 我们需要一系列繁琐的前奏. tolua++: 这是必备工具 ...
随机推荐
- Spring控制反转(IOC)和依赖注入(DI),再记不住就去出家!
每次看完spring的东西感觉都理解了,但是过了一段时间就忘,可能是不常用吧,也是没理解好,这次记下来. 拿ssh框架中的action,service,dao这三层举例: 控制反转:完成一个更新用户信 ...
- oracle 小题
create table student(sno varchar2(10) primary key,sname varchar2(20),sage number(2),ssex varchar2(5) ...
- jQuery - 自定义伪类 [:pseudoclass]
有两种创建伪类的方法, 第一种, $.extend( $.expr[':'], { // 自定义的伪类名称:group group: function(element, index, matches, ...
- 未能从程序集“System.ServiceModel, Version=3.0.0.0问题解决
在Windows Server 2008中的IIS服务器中部署WCF服务程序时,通过浏览器访问报出如下错误: 未能从程序集“System.ServiceModel, Version=3.0.0.0, ...
- 【转载】Bandits for Recommendation Systems (Part I)
[原文链接:http://engineering.richrelevance.com/bandits-recommendation-systems/.] [本文链接:http://www.cnblog ...
- 首次创建maven项目的准备工作
需要JDK1.5以上.Eclipse.maven maven下载地址:http://maven.apache.org/download.cgi 1.配置环境变量新建系统变量M2_HOME 2.运行cm ...
- 工作随笔——Swift中的Range和一些字符操作
截取字符串在Swift中相比OC要复杂很多,主要原因可能还是OC的NSRange的创建方法中参数类型为int,而Swift却对类型要求很严格,int不能作为参数创建Range,这要使用String中的 ...
- php图片处理类库 Image
image 下载地址 https://github.com/Intervention/image.git 下载之后解压 执行composer update 生成 autoload.php文件 该类 ...
- rhel 5.8下静默安装oracle11gr2
1.图形界面下录制脚本如下: #-------------------------------------------------------------------------------# Do ...
- Java学习笔记:控制反转
控制反转(Ioc)模式(又称DI:Dependency Injection)就是Inversion of Control,控制反转.在Java开发中,IoC意味着将你设计好的类交给系统去控制,而不是在 ...