[英]Lua: table.remove does not work with 2D array
t = {
{ 7, "123" },
{ 8, "234" },
{ 9, "345" }
}
t = table.remove(t, 1) -- This thing brokes everything, but should delete first group
for k, v in ipairs(t) do
print(k, v[1], v[2])
end
This thing just hates me, I fighting with it for 4 hours and ca not move from dead point. 这东西只是讨厌我,我和它战斗了四个小时,从死角上走不了。 Tried several different loops, different letters positions (
v[1] -> k[1]
, etc), nothing helps. 尝试了几个不同的循环,不同的字母位置(
v[1] -> k[1]
等),没有任何帮助。
table.remove
returns the removed element, not the updated table. table.remove
返回删除的元素,而不是更新的表。 Just don't assign t = table.remove(t, 1)
but instead discard the return value, ie a bare table.remove(t, 1)
without any assignment. 只是不分配
t = table.remove(t, 1)
,而是丢弃返回值,即没有任何分配的裸table.remove(t, 1)
。
See also the manual : 另请参阅手册 :
table.remove (table [, pos])
table.remove(表[,pos])
Removes from table the element at position
pos
, shifting down other elements to close the space, if necessary.从表中删除位置
pos
元素,如有必要,向下移其他元素以关闭空间。 Returns the value of the removed element.返回已删除元素的值。 The default value for
pos
isn
, wheren
is the length of the table, so that a calltable.remove(t)
removes the last element of tablet
.pos
的默认值为n
,其中n
是表的长度,以便调用table.remove(t)
删除表t
的最后一个元素。
t = {
{ 7, "123" },
{ 8, "234" },
{ 9, "345" }
}
table.remove(t, 1)
for k, v in pairs(t) do
print(k, v[1], v[2])
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.