LUA 元表与元方法
来源:互联网 发布:红警2 mac os10.12 编辑:程序博客网 时间:2024/05/02 02:55
元表操作:
setmetatable(table, metatable)
getmetatable(table)
元方法操作:
metatable.元方法 = function (可接受参数)
(函数体)
end
元方法:
算数运算符:__add(加法)[+]、__mul(乘法)[*]、__sub(减法)[-]、__div(除法)[/]、__unm(相反数)[-]、__mod(取模)[%]、__pow(乘幂)[^]。
逻辑运算符:__eq(等于)[=]、__lt(小于)[<]、__le(小于等于)[<=]。
其他运算符:__concat(连接)[..]、__len(取长度)[#]。
其他元方法:
__tostring:返回值(可接受参数:table)
__call:函数调用(可接受参数:table, key)
__metatable:保护元方法(字符串)
__index:查找表索引(可接受参数:table, key)
__newindex:添加新索引(可接受参数:table, key, value)
setmetatable(table, metatable)
getmetatable(table)
元方法操作:
metatable.元方法 = function (可接受参数)
(函数体)
end
元方法:
算数运算符:__add(加法)[+]、__mul(乘法)[*]、__sub(减法)[-]、__div(除法)[/]、__unm(相反数)[-]、__mod(取模)[%]、__pow(乘幂)[^]。
逻辑运算符:__eq(等于)[=]、__lt(小于)[<]、__le(小于等于)[<=]。
其他运算符:__concat(连接)[..]、__len(取长度)[#]。
其他元方法:
__tostring:返回值(可接受参数:table)
__call:函数调用(可接受参数:table, key)
__metatable:保护元方法(字符串)
__index:查找表索引(可接受参数:table, key)
__newindex:添加新索引(可接受参数:table, key, value)
阅读全文
1 0
- Lua元表与元方法介绍
- Lua元表与元方法
- Lua中的元表与元方法
- Lua中的元表与元方法
- Lua中的元表与元方法
- Lua中的元表与元方法
- lua 元表与元方法
- Lua中的元表与元方法
- LUA 元表与元方法
- Lua 元表 元方法
- Step By Step(Lua元表与元方法)
- Lua:元表(metatable)与元方法(meatmethod)
- Lua:元表(metatable)与元方法(meatmethod)
- Lua:元表(metatable)与元方法(meatmethod)
- Lua语言学习之元表与元方法
- Lua中的元表(metatable)与元方法(metamethod)
- 11.lua学习笔记:元表与元方法
- Lua:元表(metatable)与元方法(meatmethod)
- 【剑指offer】面试题45:把数组排成最小的数
- 基于Linux的网络平台
- HBase Shell及JavaAPI操作
- VMware虚拟机克隆Linux系统后找不到eth0网卡的问题解决
- Spring-国际化信息02-MessageSource接口
- LUA 元表与元方法
- LUA 构造类
- Hibernate中的lazy(懒加载)属性
- 数据库事务隔离级别
- Hibernate的悲观锁和乐观锁
- hibernate中session的线程安全问题
- POJ 1009 Edge Detection
- [Design Pattern]Python设计模式——工厂方法
- 【Leetcode】【python】Longest Common Prefix