【lua】小计setmetatable
来源:互联网 发布:淘宝茶叶散装也需要qs 编辑:程序博客网 时间:2024/05/16 12:14
local base = {x = 5, y = 10, width = 100, height = 100}base.__index = basefunction base:new() local obj = {} setmetatable(obj, self) return objendfunction base:Print() print('x:' .. self.x) print('y:'.. self.y) print('width:' .. self.width) print('height:'.. self.height)endlocal child = { color = 'red', size = 100 }child.__index = childsetmetatable(child, base)function child:new(color, size) local obj = base:new() setmetatable(obj, self) obj.color = color obj.size = size return objendfunction child:Print() print('x:' .. self.x) print('y:'.. self.y) print('width:' .. self.width) print('height:'.. self.height) print('color:' .. self.color) print('size' .. self.size)endlocal c = child:new('blue', 1000)c:Print()local b = base:new()b:Print()
一直对lua中的metatable不是很清楚,今天试了试,并没有想象中那么难。
- 【lua】小计setmetatable
- lua setmetatable实现继承
- lua setmetatable __index __newindex
- 了解lua setmetatable和__index
- 了解lua setmetatable和__index
- 学习Lua setmetatable Lua 元表
- lua的table+setfenv+setmetatable陷阱
- Lua的类实现继承、多态以及setmetatable方法
- 了解lua setmetatable和__index的小例子
- 了解lua setmetatable和__index的小例子
- Lua的类实现继承、多态以及setmetatable方法
- Lua的类实现继承、多态以及setmetatable方法
- Lua中metatable说明及setmetatable的使用
- Lua的类实现继承、多态以及setmetatable方法
- Lua的类实现继承、多态以及setmetatable方法
- Lua的类实现继承、多态以及setmetatable方法
- 了解lua setmetatable和__index的小例子
- 了解lua setmetatable和__index的小例子
- hdu1873(看病要排队)
- IE下框架不显示问题的解决办法
- Linux为用户添加sudo权限
- Cisco VPN 5.02 on Vista will not uninstall
- c# 自带进制转换
- 【lua】小计setmetatable
- c++必看书目
- Maven 学习之旅-maven的安装
- XCode中文乱码
- java clone方法使用详解
- hdu2154(跳舞毯)
- 构建自己的不可替代性 肖舸
- 认识创建型模式---工厂方法模式
- light oj 1231-1232 - 1233- Coin Change 背包