lua-users home
lua-l archive

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


On Mon, Jul 20, 2020 at 12:40 PM Lorenzo Donati wrote:
{:1000,2000:...} -- preallocate 1000 array and 2000 hash slots
{:nil,2000:...} -- preallocate 2000 hash slots
{:"noresize":...} -- table whose number of entries cannot change
{:"const": ....} -- table that cannot be changed
{:"weak":...}
{:"ephemeron":...}

We already have a syntax for optional attributes, so why invent a new one?
Just allow a table constructor to have optional attribute:

{...} <size 1000,2000>
{...} <size 0,2000>
{...} <size 0,2000 noshrink>
{...} <const>
{...} <weak>
{...} <ephemeron>

This doesn't break existing code: all these expressions were syntax errors in previous Lua versions.
The parser should look ahead three lexemes to decide whether it is an attribute or not.
Attribute has highest priority:
func{...} <weak>
is equivalent to
func({...} <weak>)