lua-users home
lua-l archive

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

Matthew Wild wrote:
> It's the opposite of unpack(). If you have, say... a function that
> returns multiple values or a vararg ... then you can't safely use
> {...} and know how many items were returned (in case of some being
> nil). table.pack helps by setting n equal to the number of items (such
> that t.n might not equal #t).
> Matthew

Yes, but you can replicate this in one line of lua code, and generally
stuff that simple doesn't get included in the standard library:

function table.pack(...)
    return { n = select('#', ...); ... }

(Thanks to #lua for this implementation.)