lua-users home
lua-l archive

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

you can use __newindex,__index like:

-- vector

-- metatable
     print("Getting value of "..k)
     return rawget(t.prop,k)
     print("Setting value of "..k.."="..v)

Your C function must crate a metatable with "__index" and "__newindex" 
functions, those functions will catch assignments. In fact, there's no reason
to carry a "prop" subtable, __index and __newindex could use your C-struct 
directly if they are C-functions.


On Mon, Jun 14, 2004 at 10:48:02AM -0400, 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?
>   My C function pushes a table into Lua that represents a struct.  If I
> could catch assignments to the table elements then I could easily allow
> intuitive (ie non Get / Set function oriented) writing to my structs.  Of
> course __newindex doesn't work, because I need to know when existing
> elements are assigned new values, not when new indices are created.
>   Thanks.
>   Dan East