lua-users home
lua-l archive

Re: __newindex rawsetless semantics?

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


On 14/10/14 05:39 PM, Tim Hill wrote:
On Oct 14, 2014, at 4:42 AM, Thiago L. <fakedme@gmail.com> wrote:
Hi,
I guess you can claim this is a proposal but I also want feedback on it...
The idea is new semantics for __newindex so you can use it without rawset():
function __newindex(t,k,v)
 if condition then
 return k,nv
 elseif othercondition then
 return nk,v
 elseif anothercondition then
 return nk,nv
 else
 return k,v
 end
end
Unless your __newindex returns junk, this shouldn't break anything.
Thanks.
I think the biggest argument against this is that it only applies to tables. What about userdata? Having the added complexity of tables be a special cases doesn’t seem to be warranted by the minor convenience.
—Tim
For userdata it would end up in an attempt to rawset(ud,k,v) :P

AltStyle によって変換されたページ (->オリジナル) /