lua-users home
lua-l archive

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


jimmyp@hal.csd.auth.gr:
>I didn't see a metamethod for the assignment operator in the

Luiz Henrique de Figueiredo:
> The metamethods are set for the table of globals, which you get using
> "getglobals()". Set "__index" and "__newindex" metamethods for this table.

jimmyp@hal.csd.auth.gr:
> I see... but won't this interfere with normal lua variable assignment?

Yah.

And if you want to make your C-synced variable local in scope then you've
got a problem. In fact, I think it can't be done. :-(

In essence, this is because Lua is untyped (the data has types but the
variables don't) so intercepting operations on variables (as opposed to
data) requires special treatment.

In Lua4 there was special treatment for global accesses. As globals are
stored in a Lua table, in Lua5 this was simplified by allowing access to
that table and using data access metamethods. Local variables, however, are
still left unhandled.

*cheers*
Peter Hill.