当前位置:网站首页>lua杂记
lua杂记
2022-08-11 05:31:00 【星际行走】
用传入索引拼接的key值,从table中获取对应的value
self.cardBaseCfg["attr"..index]
传入的index不同,可以获取不同的配置表属性。如果index为1,即相当于self.cardBaseCfg.attr1
判断table是否为空的正确做法
利用next函数
if next(a) ~= nil
--不是空表
else
--空表
end
如果a是数组,那么#a返回的是数组的长度,直接判断#a == 0就可以了。这个的前提是:a必须是数组才能这样做
链接:lua 判断table是否为空的正确做法_斧冰-CSDN博客_lua 判断table是否为空
Lua table中安全移除元素的方法
从后往前删除
for i = #test, 1, -1 do
if remove[test[i]] then
table.remove(test, i)
end
end
获取 table 的长度
list类型的,直接用#就行。其他的table无论是使用 # 还是 table.getn 其都会在索引中断的地方停止计数,而导致无法正确取得 table 的长度。
可以使用以下方法来代替:
function table_leng(t)
local leng=0
for k, v in pairs(t) do
leng=leng+1
end
return leng;
end
删除Table元素的两种方法
1、将字段赋值为 nil,适用于字典
2、使用Table库里的 table.remove(table, index),使用于列表
边栏推荐
猜你喜欢
Node stepping on the pit 80 port is occupied
OpenGL WSAD按键操作和鼠标移动操控摄像机Camera类
详解程序执行过程
swagger错误:WARN i.s.m.p.AbstractSerializableParameter - [getExample,421] - Illegal DefaultValue null
【LeetCode-350】两个数组的交集II
虚拟机更改IP地址
【剑指offer系列】面试题日记(前期题)
The official website of OpenMLDB is upgraded, and the mysterious contributor map will take you to advance quickly
CLR via C# 第一章 CLR的执行模型
自己动手写RISC-V的C编译器-02语法描述方法和递归下降解析
随机推荐
父子节点数据格式不一致的树状列表实现
mk file introduction
JS this关键字
JS事件循环机制
Lua 快速入门(六)——基础OOP
nepctf Nyan Cat 彩虹猫
USB in NRZI to encode the data
C-自定义类型(结构体、枚举、联合)
Jetpack's dataBinding
Pinyougou project combat notes
Unity两种VR环境配置方法
8-byte standard request parsing during USB enumeration
[Meetup Preview] OpenMLDB+OneFlow: Link feature engineering to model training to accelerate machine learning model development
一文看懂注解与反射
Day 86
The whole process of Tinker access --- Compilation
Unity 数字跳字功能
The role of the port
虚拟机更改IP地址
星盟-pwn-babyfmt