lua-users home
lua-l archive

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


Dear Santa,

This Christmas I would like the ability to do something like this:

 metatable.__pass = function( thing )
    return thing:copy()
 end
 a = b    -- => a = getmetatable(b).__assign(b)

 metatable.__assign = function( thing )
    return thing:copy()
 end
 some_function( a )    -- => some_function( getmetatable(a).__pass(a) )


This would make it much easier to implement value-like types, which is
a personal bugbear of mine. Currently I have to make things like vec3
and matrix immutable to get around the pass-by-reference semantics of
userdata.

I'm guessing there would be significant performance implications for
making such common actions overridable, and I can think of a few
problems with the above, but I'm curious as to whether this has been
considered before.

Thanks,
Mike F

PS: Apologies if this is a double-post