当前位置:网站首页>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),使用于列表
边栏推荐
- C-自定义类型(结构体、枚举、联合)
- Dark Horse Event Project
- 父子节点数据格式不一致的树状列表实现
- 星盟-pwn-fog
- The mount command - mounted read-only, solution
- 【LeetCode-73】矩阵置零
- C-8月1日-递归与动态内存管理
- Getting Started with JNI
- OpenMLDB: Consistent production-level feature computing platform online and offline
- Promise.race learning (judging the fastest execution of multiple promise objects)
猜你喜欢
随机推荐
Intelligent risk control China design and fall to the ground
IndexError: index 9 is out of bounds for axis 0 with size 9;数组下标溢出问题
The whole process of Tinker access --- Compilation
C-动态内存管理
nepctf Nyan Cat 彩虹猫
【LeetCode-75】 颜色分类
第六届蓝帽杯 EscapeShellcode
OpenMLDB: Consistent production-level feature computing platform online and offline
Dark Horse Event Project
Building a data ecology for feature engineering - Embrace the open source ecology, OpenMLDB fully opens up the MLOps ecological tool chain
Day 69
The role of the port
【LeetCode-74】搜索二维矩阵
5月leetcode-C#刷题日志(持续更新中)
JS case exercise (classic case of teacher pink)
The official website of OpenMLDB is upgraded, and the mysterious contributor map will take you to advance quickly
C语言-6月12日-字符替换问题,将一个‘ ’替换为2个‘#’
OpenGL 摄像机(Camera)类的创建
【转】Unity C# 关于Attribute的使用(超实用)
Pinyougou project combat notes








