lua-users home
lua-l archive

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

> Alexey Zaytsev wrote:
>> setmetatable(t, {
>>  __ref = function(table)
>>    local tmp = {}
>>    for i, j in pairs(table) do
>>      tmp[i] = j
>>    end
>>    return tmp
>>  end
>> }) <- make "=" behave like copy.
Vyacheslav wrote:
> Ask yourself "Why do I need such feature?" and tell us the answer. We
> will suggest you standard solution.

If I may drop in, it would be very useful be able to make certain
usertypes behave as values instead of like tables. The best example is
3d vectors:

vA = Vect3(1,2,3);
vB = vA;
vB.x = 0; -- Eek! vA.x gets set to 0 here!

Builtin simple types (number, string, bool) are special cases and
there is no way to create an extension that behaves that way (without
actually changing the interpreter). For vectors, by value assignment
just makes much more sense than by reference. If you have a standard
solution to this, that would be excellent.