lua-users home
lua-l archive

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


Hi,

I hesitate to propose any Lua feature as the likelihood of it being
accepted is as slim as winning a lottery. So please read this for
entertainment only.

The topic of arrays has been discussed extensively in the past. The
proposal here is not to repeat all that, and is not a language change
proposal. Instead it is an implementation and library proposal.

First, let Lua table implementation have an internal mode - call it
fixedlength array mode. In this mode two things happen:

a) The array size is fixed and predefined, an attempt to increase
array size throws an error.
b) The hash part is disabled, i.e. an attempt to insert values into
the hash part throws an error.

We then have following table functions/properties:

table.NONE - is a special Lua value that evaluates to true, and
doesn't equal anything else, including nil
table.newarray(size) - returns an array of requested size, initialized
with table.NONE

Some additional rules:

c) Tables created this way will have the two special flags set as above.
d) Such tables may not be used as metatables.
e) Such tables may not have __index, __newindex, __len metamethods overridden.

That's it.