[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua 5.2.0 (alpha) now available
- From: James Graves <ansible@...>
- Date: Sat, 11 Dec 2010 09:20:22 -0600
steve donovan wrote:
> You are right - one might get #t==3, but luajit might disagree, etc.
> It is undefined behaviour.
Yes. Though I do like that implementation of table length (in Lua
Java?) that was posted recently.
-----------------------------------------
Just as a reminder, depending on your requirements, you might want to
use a sentinel value instead of nil.
my_nil = {} -- each table is a unique object
t:insert(1)
t:insert(my_nil)
t:insert(3)
t:insert(my_nil)
t:insert(5)
-- table t now has two 'holes' at indices 2 and 4.
assert(#t == 5) -- will be true for all Lua implementations
for i, v in ipairs(t) do
if v ~= my_nil then
print(i, v) -- just print the actual values.
end
end
James Graves