Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Lua ➜ How do you Get the length of a mixed/vectored table?

How do you Get the length of a mixed/vectored table?

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by WillFa   USA  (525 posts)  Bio
Date Wed 20 Aug 2008 09:46 PM (UTC)
Message
Is there a simpler way than looping through the table and counting the keys? I know #Table only returns the contiguous arrayed portion of the table.
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #1 on Wed 20 Aug 2008 09:48 PM (UTC)
Message
No, if you mix integer and string keys, there is no way to get the length other than by counting. (Actually, there are some gotchas even if you use only integers, depending on whether or not you have holes and how big they are.)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by WillFa   USA  (525 posts)  Bio
Date Reply #2 on Wed 20 Aug 2008 09:53 PM (UTC)
Message
Yup. I know about the gotchas.

I mainly wanted to know because I was looking for a way to see if the table's empty.

"if next(Table) then ..." solves that problem.
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #3 on Wed 20 Aug 2008 09:59 PM (UTC)
Message
Ah -- yes :) That's what the Lua people have always said: usually when people want the length, what they really want is to check if the length is zero...

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


10,788 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.