lua-users home
lua-l archive

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


On Thu, Jul 29, 2004 at 01:07:38PM +0200, David Anderson wrote:
> Hi all,
> 
> I am writing some lua glue to keep the values in a (minimal) structure 
> in the C core in sync with the corresponding values in a (much bigger) 
> table in the lua environment. At first I had thought I could use the 
> __index (via a proxy table) element of the metatable to trigger 
> callbacks in the C code whenever the values I monitor are accessed.
> 
> However, the __index function gets called before the values are actually 
> updated (makes sense), so at that stage I don't know if I need to call 
> the C funcs (has the value changed?), and I don't know the new value, as 
> it only gets affected after __index runs through.
> 
> Looking through the manual and book, I can't find any metatable entry 
> that would act as a postnotification, something like:

__newindex is exactly what you want. Remember that your proxy table is
empty (or should be :-), so any 'modification' looks to Lua like you
are creating a new table entry.

-- Jamie Webb