[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Feature Request: rawset return value from __newindex
- From: Patrick Donnelly <batrick@...>
- Date: Wed, 19 Oct 2011 20:16:36 -0400
On Wed, Oct 19, 2011 at 8:12 PM, Daurnimator <quae@daurnimator.com> wrote:
> A small feature request to distract you all from the noise on the list recently:
>
> I often find myself writing code like
> mt.__newindex = function ( t , k , v )
> v = dosomethingwithv ( v )
> rawset(t,k,v)
> end
>
> Could we make it so the return value of __newindex is then set as the
> value in t?
Consider proxy tables. You never actually add anything to the proxy
table. All indexes and sets are redirected. e.g.
t = {}
proxy = {}
setmetatable(proxy, {__index = t, __newindex = function(_,k,v) t[k] = v end})
[I think you can actually just set __newindex to t, but this should
work regardless.]
--
- Patrick Donnelly