[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Redefine "=".
- From: "Jérôme VUARAND" <jerome.vuarand@...>
- Date: Thu, 1 Jun 2006 22:27:32 -0400
t = {}
setmetatable(t, {
__newindex = function(self, key, value)
print("Hello World! ("..key..value..")")
end
})
t["foo"] = "bar"
Hello World! (foobar)
There is a strong distinction between variables and values in Lua.
Variables are merely references to values. In :
t = "foo"
you are not affecting a value to the above table, you are affecting a
new value to an untyped variable (t). But you cannot set metatable for
variables, only for values. That's a good reason for not having a kind
of __reference or __copy metamethod.
2006/6/1, Alexey Zaytsev <alexey.zaytsev@gmail.com>:
Hello.
Is it possible to redefine the reference ("=") operator for tables in lua?
I thougth it is a job for metamethods, but could not find any. Is
there any reason for not having any __reference (or __copy) metamethod
in lua?