lua-users home
lua-l archive

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

On Sun, Feb 7, 2010 at 6:50 AM, Wim Langers <> wrote:
> Just something that struck me as being odd the other day...
> table.insert(table[,pos],data)
> --> has the second parameter optional instead of the third ?
> switching this to
> table.insert(table,data[,pos])
> would, beside a perhaps unprecedented level of incompatibility between
> versions, give the advantage of being able to use a position parameter
> calculated from "unusual" conditions (that return a nil result to indicate
> out of range parameters or such).

Use this:

table.insert(table, getpos(...) or #t+1, data)

where #t+1 is the default position for table.insert (or whatever you
want the default to be).

- Patrick Donnelly