[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: new "empty" value/type in Lua?
- From: Luis Carvalho <lexcarvalho@...>
- Date: Tue, 2 Jul 2013 22:08:36 -0400
Coda Highland wrote:
> On Tue, Jul 2, 2013 at 5:34 PM, Luis Carvalho <firstname.lastname@example.org> wrote:
> >> Is something like this enough? (Note that 'n' is *not* hidden; I do
> >> not think hidden stuff is good in the end...)
> > Agreed. I had a very similar version, but required that only integer keys can
> > be set in __newindex and setlength is implemented through __call:
> You didn't put in a way to shrink the array. Probably sufficient to
> handle calling newindex on n, I suppose.
No, since 'n' is an existent field (so newindex won't be called.) You can grow
the array by setting a[k] for k > t.n, but to really shrink -- that is, to set
t[k] = nil for k > n -- you have to use __call: a(n). That's just a matter of
taste, and it might be better to have an explicit setlength as in Roberto's
implementation, but I thought that shrinking the array would be rare and not
worth of a dedicated method (and setting __index.)
Computers are useless. They can only give you answers.
-- Pablo Picasso
Luis Carvalho (Kozure)
lua -e 'print((("lexcarvalho@NO.gmail.SPAM.com"):gsub("(%u+%.)","")))'