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

Storing anything in index 0 does not effect the length operator. #6

Open
ghost opened this issue Nov 19, 2013 · 3 comments
Open

Storing anything in index 0 does not effect the length operator. #6

ghost opened this issue Nov 19, 2013 · 3 comments

Comments

@ghost
Copy link

ghost commented Nov 19, 2013

-- nils don't count
local list = {}
list[0] = nil
list[1] = "item"

print(#list) -- 0
print(select('#', list)) -- 1

@catwell
Copy link
Contributor

catwell commented Nov 20, 2013

Yes, moreover I think the example is actually wrong. #list will be 1 here...

catwell added a commit to catwell/lua-style-guide that referenced this issue Nov 20, 2013
- better explanation of the length operator
- no functions in table constructors
- spaces after { and before }
@LPGhatguy
Copy link

Another note for this (several years later) is that the use of select is misleading here.

select has nothing to do with tables, of course passing in list as the second parameter is going to yield 1!

@catwell
Copy link
Contributor

catwell commented Aug 4, 2017

Yes, I removed it in my commit (several years ago) :)

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

2 participants