LUA 删除元素的问题
2024-08-25 00:38:14
table在删除元素时要注意,例
t = { "hello", "world", "!"}
t[1] = nil
此时print(#t) --输出3,就是说把表的元素置为nil并没有移除该表项。
但,若是:
t = {
[] = nil,
[] = ,
[] = nil
} function count(t)
local c =
for k, v in pairs(t) do
c = c +
end
return c
end print(count(t))--1
再看更诡异的
t = {
[] = ,
[] = nil,
[] =
} function count(t)
local c =
for k, v in pairs(t) do
c = c +
end
return c
end print("------------------", #t)
t2 = { "hello", "world", "!"}
t2[] = nil
t2[] = nil
t2[] = nil
print("--------t2---------", #t2)
for k, v in pairs(t2) do
print(k, v)
end print("--------------->")
for i=, #t2 do
print(i, t2[i])
end
最新文章
- Android之实现ViewPagerIndicator
- [转载] Can't create table './store/#sql-b2c_1a.frm' (errno: 150)和sql execution error #1452添加外键时错误解决方法
- 让Session失效的三种方法
- Android应用插件式开发解决方法[转]
- ios8.1.2耗电情况严重的解决方法
- Mindset + Know-how+Concepture + Methodology+Technology
- windows下实现linux的远程访问以及linux上文件的上传和下载
- HDU - 1407 打表
- console.log 简写
- 关于查找iOS中App路径时所要注意的一个问题
- [ Servlet / JSP ] J2EE Web Application 中的 JSESSIONID 是什么?
- 将 ASP.NET Core 2.0 项目升级至 ASP.NET Core 2.1.3X
- Linux操作系统配置Go语言编程环境
- 链表(list)使用注意
- C# 实现Bezier曲线(vs2008)
- Star HDU1541
- Go语言中Socket通信TCP服务端
- Spark2 Dataset之collect_set与collect_list
- js 兼容各类手机 的写法 待续
- Readme.MD 例子
热门文章
- python模块之ConfigParser: 用python解析配置文件
- Eclipse CDT 配置C /C ++ 标准库 (UBUNTU 12 )
- 记c#中构造函数中this的用法
- Git Error: warning: refname 'origin/branch-name' is ambiguous.
- Cause: org.postgresql.util.PSQLException: ERROR: cached plan must not change result type的前因后果
- 【转】Linux下同时复制多个文件
- Struts2自定义标签3模仿原有的s:if s:elseif s:else自定义自己的if elsif else
- ballerina 学习二十 http/https
- leetcode:Insert Sort List
- python删除x天前文件及文件夹