[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Adding several methamethods could be helpful
- From: Daurnimator <quae@...>
- Date: Sun, 27 Mar 2011 20:41:55 +1100
On 27 March 2011 08:54, Rebel Neurofog <firstname.lastname@example.org> wrote:
> My suggestion is about implementing '*=', '/=', '-=', '+=', '%=' and
> '^=' operations for user data and tables only.
> I would name that "__mulself", "__divself", "__subself", "__addself",
> "__modself" and "__powself".
> This would be helpful in code like that:
> function translate_rotate (source_matrix, translation, rotation)
> -- source_matrix is 'mat4' userdata
> -- translation is 'vec3' userdata
> -- rotation is 'quaternion' userdata
> local destination_matrix = source_matrix.translate translation()
> destination_matrix *= rotation
> return destination_matrix
> Since we are dealing with mutable data, this could be very helpful for
> efficiency still keeping module API sweet.
> On the other hand, I'm strictly against using these things on
> immutable data types (like 'sum += 3.5' for 'sum = sum + 3.5'):
> Lua must not turn into messy thing like Python.
> What do you think?
I do see merit in this; many times I've been bitten by not being able
to reuse memory in calculations
==> a temporary object (for c*d) is created; and using one of the
operand's memory is difficult, if not impossible for some