lua-users home
lua-l archive

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


On 7 July 2016 at 17:15, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> We've had several threads and I can't without re-reading everything
> give credit where credit is due, but the following ideas for fixed-length
> tables seem to be useful enough to keep in mind.
>
> 1. The __len metafield could contain an integer, not a function.

No. You don't want a metatable per array/list/sequence

> 2. That could be used to flag the table as a fixed-length array
> that may contain nils.
> 3. Supply __newindex metamethod if you want to treat an assignment
> outside the range of a fixed-length table as an error.
> 4. This will automatically cause table.insert to be an error.
> 5. The semantics of table.insert could be revised so that in the case
> of a fixed-length table, no assigment beyond __len is made, but an
> error is signalled if the last element is not nil.
> 6. Automatic resizing of a fixed-length array could be replaced
> by doing it only on request (e.g. a function table.resize).
>
> This does not seem to be too large for a PowerPatch.


None of this needs to be a patch.

See http://lua-users.org/lists/lua-l/2016-06/msg00409.html