lua-users home
lua-l archive

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


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?