Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7.2 luaTable的实现代码,删除数组末位的空自动,是否应该在找到第一个非空元素的时候结束循环? #21

Open
taoistcard opened this issue Nov 18, 2020 · 5 comments

Comments

@taoistcard
Copy link

taoistcard commented Nov 18, 2020

`

func (self *luaTable) _shrinkArray() {
for i := len(self.arr) - 1; i >= 0; i-- {
if self.arr[i] == nil {
self.arr = self.arr[0:i]
} else {
break //应该是需要break???
}
}
}
`

@qazwsxedc121
Copy link

我也是看到这里一直想不明白,应该要break才对,求作者大大解答一下 @zxh0

@zxh0
Copy link
Owner

zxh0 commented Mar 3, 2021

谢谢反馈,最好能写一个Lua脚本对比一下CLua和本书实现的差别😊

@qazwsxedc121
Copy link

您好,我用的测试脚本如下:

tb = {"a", "b", "c", "d", "e"}
tb[3] = nil
tb[5] = nil
print(tb[4])

在CLua中运行,可以得到正确结果tb[4]是 “d”
但用书中的代码,tb[4]是nil,在Shrink后的结果中被丢掉了

@zxh0
Copy link
Owner

zxh0 commented Mar 5, 2021

@qazwsxedc121 收到,我会尽快处理一下

@zxh0
Copy link
Owner

zxh0 commented Mar 6, 2021

@taoistcard @qazwsxedc121 已经提交了fix,非常感谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants