lua-users home
lua-l archive

Re: Possible Lua enhancements (mostly for private data)

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


On Thu, Dec 18, 2008 at 2:26 AM, David Manura <dm.lua@math2.org> wrote:
> On Wed, Dec 17, 2008 at 4:33 PM, Mark Hamburg wrote:
>> So, now we can write:
>> label _angle, _radius
>> function Point( x, y )
>> return {
>> _angle = math.atan2( y, x ),
>> _radius = math.sqrt( y * y + x * x ),
>> coordinates = function( self )
>> return self._radius * math.cos( self._angle
>> ), self._radius * math.sin( self._angle )
>> end
>> }
>> end
>
> You can achieve a similar effect with "inside-out objects"[1-2] via
> Lua's support for weak keys.
I'm probably missing something, but why use this method and not
closures? That is, why not define "angle" and "radius" as upvalues,
along with "self"?
Matthew.

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