Pharap, on 18 August 2012 - 03:40 PM, said:
Ponder, on 18 August 2012 - 01:08 PM, said:
In the first example you create two different tables even though they have the same content. They have to be stored in different locations in memory, because tables are mutable.
In the second example you only create one table, but have it referenced by two variable name. Hence there is only one table stored in memory and since tab1 and tab2 are pointing to the same chunk of memory they are the same.
local var1 = 5
local var2 = 5
if var1 == var2 then print("true") else print("false") end
The result would be true, contradicting the way tables are handled.In almost any other language, the two tables would be declared equivalent.
If lua was going to implement pointing to memory, surely it would make more sense to handle it like C++ and have an operator for it. It's just plain awkward doing it otherwise.
Nope, since integers are immutable, there is no need for the interpreter to create two chunks of memory which hold the same value. In your example both var1 and var2 are pointing to the same location and are therefor equal.
That is if I remember correctly, been some time since I read about it.
I do agree with you however that Lua's behavior is irritating there and there should be something like a "is" operator which does that kind of thing.


Posted by
