lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hans van der Meer wrote:
Trying to find in C program the length of a table with lua_objlen that returned zero, though there are entries in the table (I made them myself).

Both are tables, the former gets length 0, the latter length 3.
Surely there are entries in the first because the following program shows it:
Quote from manual:
The length of a table |t| is defined to be any integer index |n| such that |t[n]| is not *nil* and |t[n+1]| is *nil*; moreover, if |t[1]| is *nil*, |n| may be zero. For a regular array, with non-nil values from 1 to a given |n|, its length is exactly that |n|, the index of its last value. If the array has "holes" (that is, *nil* values between other non-nil values), then |#t| may be any of the indices that directly precedes a *nil* value (that is, it may consider any such *nil* value as the end of the array).

/Erik