Dirk and I have been working on a prototype of a full replacement for Lua's table library and this is now ready to be exposed to a wider audience. The main innovations are:
- All functions that need the list length (len) have an optional extra first parameter allowing len to be specified directly. Using this parameter completely decouples the function from Lua's #.
- 'insert' and 'delete' now work with multiple values.
- The 'pos', 'first' and 'last' parameters allow negative indexes with the same interpretation as the string library i.e. -1 means # etc. This also prevents the 'insert' function even trying to insert a negative or zero key (why did Lua ever allow that?).
- The '__len' metamethod is overloaded to allow our 'insert' and 'delete' replacements to call it notifying it of changes to list length. A new 'list' function attaches a standard metatable which uses this mechanism storing the length in tab[tab] which is much less likely to cause name clashes than 'n'.
- 'concat' does proper concatenation using any '__concat' metamethods and may produce a return of any type. Any separator is treated the same way as the values and may be of any type.
- 'sort' gains 'first' and 'last' parameters.
- 'pack' returns extra parameters reporting the element count and whether or not the table contains a 'proper sequence'.
- When using the default length determination method (i.e. edge detection), the 'insert' function errors on parameters that would break 'proper sequence' i.e. it does not allow insertion of 'nil' values and it only allows the table to grow contiguously from the top.
Dirk hates item 8 and despite a lengthy and occasionally acrimonious exchange of emails we've not reached a shared understanding of what the reason for the objection is, let alone agreement on whether it should be in or out!
If we allow a little latitude in the definition of 'value', xtable gives the same results as documented in Lua 5.2 Reference Manual for the table library, given the same parameters.
We are seeking views on whether/how to release this into the wild. A draft User Manual is attached.