[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Re: Definition of table.insert
- From: steve donovan <steve.j.donovan@...>
- Date: Sun, 9 Jan 2011 12:04:16 +0200
On Sun, Jan 9, 2011 at 11:46 AM, GrayFace <sergroj@gmail.com> wrote:
> Wouldn't it be even better if you write
> local v = get_next_task()
> if v ~= nil then
> table.insert(t, #t, v)
> end
Or even just table.insert(t,v). This currently works as well without
the if-guard, but I can't recommend that without some guarantees about
table.insert.
If the task being nil is important, then the 'sentinel' pattern is useful.
local null = {}
....
table.insert(t,v or null)
No holes!
steve d.