lua-users home
lua-l archive

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




On Mar 17, 2018, at 5:16 AM, Egor Skriptunoff <egor.skriptunoff@gmail.com> wrote:

More details:
1) Setting new "user-specified length" does not remove anything
from the table.
2) "user-specified length" must be changed automatically by some
standard "table"-library functions according to their semantics
(only when "user-specified length" is a number).
3) When user grows/shrinks array manually, he/she must modify
"user-specified length" manually.
Old idiom for appending a new value to an array
   t[#t + 1] = next_value
should be replaced with new idiom:
   #t = #t + 1
   t[#t] = next_value

4) New metamethod __setlen is needed.

I guess this improvement of old good "t.n" would solve most of the problems
related to arrays, tuples, nils in tables, and strange array length algo.

I suggested something very much like this some time ago. Only feedback was the overhead of storing an extra integer (size) in each table (which imho is usually zero overhead since most allocators are sufficiently course-grained this is lost in the allocation).

The big advantage to me is that it’s 100% backward compatible .. if you dont use manual length you get existing behavior.

—Tim