[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: getn
- From: "Nick Trout" <nick@...>
- Date: Fri, 24 Aug 2001 16:28:38 +0100
Is there any chance that the table entry used to store the number of elements,
ie. n, can be renamed to something less likely to cause a name clash with user
code?
eg. _n or __n__
getn (table)
Returns the ``size'' of a table, when seen as a list. If the table has an n
field with a numeric value, this value is the ``size'' of the table. Otherwise,
the ``size'' is the largest numerical index with a non-nil value in the table.
This function could be defined in Lua:
function getn (t)
if type(t.n) == "number" then return t.n end
local max = 0
for i, _ in t do
if type(i) == "number" and i>max then max=i end
end
return max
end
Nick
---
Criminal: A person with predatory instincts who has not sufficient capital to
form a corporation.
- Howard Scott