Announcement

Collapse
No announcement yet.

Table.Count incorrect if table contains one more more nil values

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Table.Count incorrect if table contains one more more nil values

    I just noticed that Table.Count only counts non-nil values. For example:

    tbl = {"hello", nil, "world"};
    tblcount = Table.Count(tbl);

    tblcount is equal to 2 instead of 3. Is this a bug or a feature? Is there a way to get the actual Table count?

    I also tried using LUA function table.getn with different, but still incorrect results.

    I am using SUF 9.2.

  • #2
    This is how tables work in Lua. All tables are handled as associative arrays, and an element set to nil "does not exist".
    If you use numeric indices, then you can use the Lua function table.maxn() for returning the maximum index, even if there are holes in the table.

    Ulrich
    Last edited by Ulrich; 10-28-2014, 03:31 PM.

    Comment

    Working...
    X