[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua as (Matlab like) calculator
- From: steve donovan <steve.j.donovan@...>
- Date: Tue, 28 Jun 2011 10:35:06 +0200
On Tue, Jun 28, 2011 at 10:25 AM, Oscar Chinellato
> official Lua team (in a robust and proper way), however, any hints on
> how to correctly implement this additional metamethod would be greatly
This is for user-defined types, yes? Because objects-as-references is
the standard Lua way of thinking. It is not (as you say) what
assignment means in a mathematical sense of course.
The __newindex metamethod does get you part of the way. In fact, by
giving the global environment a suitable __newindex, you can get what
you want, although it will not work with local variables (which are
not table references)
So, if A is global (or in the current environment, since you can
customize this for your scripts) then
A = 1
can be made to fire __newindex on the environment, if A does not
So store it as _A and define a __index metamethod to prepend '_' when
it's trying to resolve a symbol.
You now have a way to hook into both assignment and variable access.
However, this is not going to happen when passing in a value to a
function, I'm afraid.