lua-users home
lua-l archive

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


Two related comments about 5.2 alpha.

First, is feels like asking for trouble that table.pack() and
table.unpack() aren't symmetrical, despite names that strongly suggest
that they are.
  function foo(...) return ... end
and
  function foo(...) return table.unpack(table.pack(...)) end
behave differently in the face of trailing nils.

In particular, since table.pack uses lua_createtable() with a size
argument, the above two functions will happen to do the same thing if
the last argument to them is not nil.  This seems like an accident of
the implementation.  It's probably dangerous to rely on (what if the
user copies or serializes the table somehow?) and may help support
common misconceptions of how # works.

The above led me to think that the result of table.pack() might want a
metatable where __len returns the larger of n and the raw length.
Then I realized you can't write this in Lua 5.2.  The standard library
probably needs a rawlen() function, by analogy to rawget()/rawset().

Greg F