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中模 ...
随机推荐
- C#写的一个视频转换解码器
C#写的一个视频转换解码器 using System; using System.Collections.Generic; using System.Linq; using System.Text; ...
- 网络编程基础——学习阻塞,非阻塞(select和epoll)
<h3 class="xyn" helvetica="" neue',="" helvetica,="" aria ...
- scp命令使下用
先说下背景把,使用ubuntu,没有windows以下到xshell软件管理一下vps.正瞅着须要下载一个chrome(chrominum真的不好用).此刻大谷歌正墙外呢,无奈挂着ss firefox ...
- (转)java 打印自身代码——真实世界不存在自指
public class SelfPrint { public static void main(String args[]) { char s = 34; ...
- .Net 使用的快捷键
快捷键 功能 CTRL + SHIFT + B生成解决方案 CTRL + F7 生成编译 CTRL + O 打开文件 CTRL + SHIFT + O打开项目 CTRL + SHIFT + C显示类视 ...
- python学习日记:np.newaxis
import numpy as np label = np.array([[1,2,3,4],[5,6,7,8]])print (label.shape)label = label[np.newaxi ...
- <转>sock代理服务原理(TCP穿透)
原文转自:http://www.cppblog.com/zuhd/archive/2010/06/08/117366.html sock代理分为sock4代理和 sock5代理.sock4支持TCP( ...
- 通过Spring使用远程访问和web服务
http://docs.huihoo.com/spring/zh-cn/remoting.html Spring2 提供的remote包学习笔记
- GEEK学习笔记— —程序猿面试宝典笔记(三)
所谓笔记,就是比較个人的东西,把个人认为有点意思的东西记录下来~~ 程序猿面试宝典笔记(一)基本概念 程序猿面试宝典笔记(二)预处理.const和sizeof 程序猿面试宝典笔记(三)auto_ptr ...
- Android JNI和NDK学习(06)--JNI的数据类型(转)
本文转自:http://www.cnblogs.com/skywang12345/archive/2013/05/23/3094037.html 本文介绍JNI的数据类型.NDK中关于JNI数据类型的 ...