lua-users home
lua-l archive

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

  I'm afraid I don't have anything in print regarding Lua.

  Thanks for the suggestion - this sort of works.  I did a quick test, and
my __newindex handler is called when a non-existent element is assigned a
value, but not when it is read:

  x=MyClass.x	--Does not trigger __newindex handler
  MyClass.x=10	--Triggers __newindex handler

  So how is reading values handled in the proxy table?

  So at this point I can catch writes, or let the user read, but not both at
once.  :)

  Dan East

-----Original Message-----
[]On Behalf Of Aaron Brown
Sent: Monday, June 14, 2004 11:02 AM
To: Lua list
Subject: Re: __assign

Dan East wrote:

>   Is there some non-trivial implementation issue that
> prevents an __assign metatable event within Lua?  Or is
> there some other mechanism already providing the same
> functionality?

It can currently be done with __newindex and a proxy table.
I don't see this explained in the wiki anywhere, but it is
on page 115 of Programming in Lua, if you have it.

Briefly, the idea is that the table the user assigns to is
always empty -- its __newindex metamethod does any
housekeeping you want done on every assignment, plus the
actual assignment to the real table (which the user never
directly accesses).