[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: userdata as table-key
- From: "Wim Couwenberg" <wcou@...>
- Date: Tue, 27 Apr 2004 18:11:03 +0200
> To be accurate (to avoid confusion for newbies...), if the n field of
> the table hasn't been changed, table.getn() returns the largest
> integer key when counting consecutive indexes from 1.
> I feel this sentence can be better formulated...
>
> In other words, the array part of a table only have consecutive
> positive integer keys starting at 1. Any other positive integer key,
> if there is a gap, isn't seen as index of the array.
Beware that "unpack" also uses luaL_getn to determine the number of
elements. This can come as a surprise in situations like the following:
-- catch return values...
local results = { f() }
-- do some more stuff here
-- return results of f()
return unpack(results)
This will drop all return values after the first nil... In this case you
could use a function "pack":
function pack(...)
return arg
end
local results = pack(f())
-- etc. etc.
--
Wim