lua-users home
lua-l archive

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


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.