[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Adding custom bulit-in type
- From: Sean Conner <sean@...>
- Date: Thu, 27 Jul 2023 19:40:31 -0400
It was thus said that the Great Roberto Ierusalimschy once stated:
> > __newindex = function(self,k,v)
> > if k == 'x' then
> > -- magic code to set x portion of self to v
> > elseif k == 'y' then
> > -- magic code to set y portion of self to v
> > end
> > end
> > }
> >
> > What am I missing?
>
> Whatever you do, __newindex receives a copy of the original 'v', not
> the original. If 'v' is/has a pointer (created with allocation), then
> the copy and the original point to the same memory, and changing that
> memory affects both 'v' and the original value. If 'v' does not
> is/has a pointer, then changing it cannot affect the original value
> that 'v' is a copy.
I take it there's no easy way to get to the underlying TValue *?
-spc