Page 1 of 1
*SOLVED* A really-really small question.
Posted: Tue Nov 18, 2014 1:46 pm
by ffive
Hi.
Um, can't find answer anywhere else..
What does number sign (#) operator do in Lua?
Re: A really-really small question.
Posted: Tue Nov 18, 2014 1:55 pm
by Doctory
gives you the size of a table.
for ex, a table has 3 items, table[1], table[2], and table[3]
if you use #table, it will return 3, because thats how much items the table has
Re: A really-really small question.
Posted: Tue Nov 18, 2014 2:12 pm
by ffive
Huge thanks!
Re: *SOLVED* A really-really small question.
Posted: Tue Nov 18, 2014 2:23 pm
by Doctory
no problem
Re: *SOLVED* A really-really small question.
Posted: Tue Nov 18, 2014 3:49 pm
by zorg
Note that it only works for the numeric part of a table (starting from 1, going until the next index is nil), so if you have gaps, then it won't report the "true" size of the table... and it doesn't count any other key either.
Re: *SOLVED* A really-really small question.
Posted: Tue Nov 18, 2014 5:46 pm
by Ref
Let's not forget strings.
str = 'This is a string'
#str returns length of str - 16.
Re: *SOLVED* A really-really small question.
Posted: Tue Nov 18, 2014 6:20 pm
by Doctory
Ref wrote:Let's not forget strings.
str = 'This is a string'
#str returns length of str - 16.
ah, cool
for up to now i've been using string.len()
thanks for this info