lua-users home
lua-l archive

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


> -----Ursprüngliche Nachricht-----
> Von: lua-l-bounces@lists.lua.org <lua-l-bounces@lists.lua.org> Im Auftrag
> von Dirk Laurie
> Gesendet: Donnerstag, 18. Oktober 2018 09:42
> An: Lua mailing list <lua-l@lists.lua.org>
> Betreff: Array subtype is conceptually simplest
> 
> An array subtype would solve that problem.
> 
> 1. Own __len, implicit in the subtype, if you set your own __len it is no longer
> an array.
> 2. ipairs iterates from 1 to __len, table functions use __len.
> 3. Value returned by __len is fixed when the table is created and can't be
> changed by assignment, only by functions in the table library (insert, remove,
> setlen).

In addition, (3) would also allow to only allocate the actual required
amount of memory for the array instead of, worst case, use almost
twice of that.