lua-users home
lua-l archive

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

> local function vector3_add(self, o)
>     local rtn = self();
>     for i=1,3 do
>        rtn[i] = self[i] + o[i];
>     end
>     return rtn;
> end
> The question is, can anyone think of a way to either:
> * Alter my object usage and design patterns to create fewer
> short-lived objects while not overly killing convenience

Here is a possible idea to eliminate the temporary objects, however I am not
sure if it would work in more complex expression evaluations:

local vector3_add_rtn = {}
local function vector3_add(self, o)
   for i=1,3 do
      vector3_add_rtn[i] = self[i] + o[i];
   return vector3_add_upvalue;

Each binary operator metamethod would have to have its own vector3_xxx_rtn