lua(仿单继承)
--lua仿单继承
Account = { balance = } function Account:new(o)
o = o or {}
setmetatable(o, self)--Account表本身作为o的metatable
self.__index = self--自己作为自己的原型
return o
end function Account:deposit(v)
self.balance = self.balance + v
end function Account:withdraw(v)
if v > self.balance then print("insufficient funds") end
self.balance = self.balance - v
end SpecialAccount = Account:new()--从Account继承所有操作 function SpecialAccount:withdraw(v)
if v - self.balance >= self:getLimit() then
print("insufficient funds")
end
self.balance = self.balance - v
end function SpecialAccount:getLimit()
return self.limit or
end s = SpecialAccount:new{limit = 1000.00}--s继承SpecialAccount,SpecialAccount继承Account
s:deposit(100.00)
这个没怎么看懂
lua(仿单继承)的更多相关文章
- 在看lua仿单继承
--lua仿单继承 Account = { balance = } --对于成员变量,第一此访问要使用元表中的,在第一次也赋值到自己的域中了 --将不涉及到__index了 function Acco ...
- cocos2dx lua中继承与覆盖C++方法
cocos2dx的extern.lua中的class方法为lua扩展了面向对象的功能,这使我们在开发中可以方便的继承原生类 但是用function返回对象的方法来继承C++类是没有super字段的,这 ...
- cocos2d-x-lua基础系列教程四(lua多继承)
lua - 多继承 1,模拟伪继承 新建extend_test.lua 新建extend_test.lua setmetable(a,b) b对象是a 对象的父类 a继承于b Account = { ...
- lua 类继承和实现
http://blog.csdn.net/ssihc0/article/details/7742323 Account={balance=}; --新建了一个对像,他有一个属性balance func ...
- Lua面向对象 --- 继承
工程结构: BasePlayer.lua: BasePlayer = {} BasePlayer.root = "BasePlayer" function BasePlayer:S ...
- Lua面向对象----类、继承、多继承、单例的实现
(本文转载)学习之用,侵权立删! 原文地址 http://blog.csdn.net/y_23k_bug/article/details/19965877?utm_source=tuicool&a ...
- 【游戏开发】在Lua中实现面向对象特性——模拟类、继承、多态
一.简介 Lua是一门非常强大.非常灵活的脚本语言,自它从发明以来,无数的游戏使用了Lua作为开发语言.但是作为一款脚本语言,Lua也有着自己的不足,那就是它本身并没有提供面向对象的特性,而游戏开发是 ...
- Lua面向对象 --- 多继承
工程目录结构: ParentMother.lua: ParentMother = {} function ParentMother:MortherName() print("Morther ...
- lua面向对象实现(实例化对象、继承、多态、多继承、单例模式)
lua面向对象实现: 一个类就像是一个创建对象的模具.有些面向对象语言提供了类的概念,在这些语言中每个对象都是某个特定类的实例.lua则没有类的概念,每个对象只能自定义行为和形态.不过,要在lua中模 ...
随机推荐
- ngrinder安装
1.源码编译和部署 官网:http://naver.github.io/ngrinder/ 下载源码后,存在部分依赖库不在maven的远程仓库中,这是可以用下载jar包后,用以下命令打包到本地仓库: ...
- POJ 2392 Space Elevator(贪心+多重背包)
POJ 2392 Space Elevator(贪心+多重背包) http://poj.org/problem?id=2392 题意: 题意:给定n种积木.每种积木都有一个高度h[i],一个数量num ...
- codeforces #550D Regular Bridge 构造
题目大意:给定k(1≤k≤100),要求构造一张简单无向连通图,使得存在一个桥,且每一个点的度数都为k k为偶数时无解 证明: 将这个图缩边双,能够得到一棵树 那么一定存在一个叶节点,仅仅连接一条桥边 ...
- 循环List<Object>
List<Object> infoData=ArrayList<>(); for (int i = 0; i < infoData.size(); i++) { Obje ...
- Android自定义Toast
1.http://www.cnblogs.com/salam/archive/2010/11/10/1873654.html 2.
- linq-to-sql实现left join,group by,count
linq-to-sql实现left join,group by,count 用linq-to-sql实现下面的sql语句: SELECT p.ParentId, COUNT(c.ChildId) FR ...
- kafka快速开始教程
此教程假设你刚刚开始没有任何 Kafka 或 ZooKeeper 数据.Kafka的控制台脚本在类Unix和Windows平台不同,Windows平台使用bin\windows\\代替bin/,脚本的 ...
- Yum Error Another app is currently holding the yum lock; waiting for it to exit
Another app is currently holding the yum lock; waiting for it to exit... The other application is: P ...
- [转载]几个开源Javascript图形库
[转载]原文地址:http://www.cnblogs.com/webgis8/articles/1516639.html 因为Google Map项目的需要,最近一直在寻求相关的Javascript ...
- c++ why can't class template hide its implementation in cpp file?
类似的问题还有: why can't class template use Handle Class Pattern to hide its implementation? || why there ...