lua-users home
lua-l archive

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


On 27 March 2011 08:54, Rebel Neurofog <rebelneurofog@gmail.com> wrote:
> Hi!
>
> 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
> end
>
> 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
eg, a=b+c*d
==> a temporary object (for c*d) is created; and using one of the
operand's memory is difficult, if not impossible for some
circumstances.

Daurn.