lua面向对象例子
来源:互联网 发布:超市行业数据 编辑:程序博客网 时间:2024/05/03 23:50
#!/usr/bin/lua-- 对象A,也是一个类型(对象与类是一个东西,称之为原型)A ={ x = 10, y = 20}function A:new(o) o = o or {} -- create object if user does not provide one setmetatable(o, self) self.__index = self return oendfunction new(o) A:new(o)endfunction A:acc(v) self.x = self.x + vendfunction A:dec(v) if v > self.x then error "not more than zero" end self.x = self.x - vend--从A中产生一个对象AA,也是子类型AA = A:new()-- 重载function AA:acc(v) self.x = self.x + v print(self.x)end-- 子类中新增的方法function AA:getx() return self.xend--此时,AA就是一个新表了,它是一个对象,但也是一个类,是AA的子类。它还可以继续如下操作:s = AA:new()--然后,现在调用s:acc(5)s:dec(10)print(s:getx())
阅读全文
0 0
- lua面向对象例子
- 【Lua】Lua之面向对象
- LUA 面向对象
- LUA面向对象浅析
- Lua 面向对象实现
- lua 面向对象
- Lua 面向对象
- Lua面向对象
- lua 面向对象编程
- lua面向对象
- lua实现面向对象
- lua面向对象思想
- lua 面向对象使用
- Lua的面向对象
- lua实现面向对象
- Lua面向对象
- lua中的面向对象
- lua的面向对象
- Python3学习(24)--内置装饰器@property
- LeetCode 35. Search Insert Position
- Let’s Encrypt免费搭建HTTPS网站
- 26.集合工具类Collections
- PL/SQL Developer 中文乱码问题
- lua面向对象例子
- i2c驱动--i2c总线接口
- HDU 3092 Least common multiple【完全背包】
- 再起航,我的学习笔记之JavaScript设计模式16(享元模式)
- IO流总结
- GLSL 内建变量
- 解决git中upstream丢失问题Your branch is based on 'origin/xxxx', but the upstream is gone.
- UVA 1601 The Morning after Halloween (优化BFS)
- 挑战程序竞赛系列(48):4.2 推理与动态规划算法(1)