lua-users home
lua-l archive

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


Ryan Leigh wrote:

> Now, I would like it if I could write a function:
>
> function myObj.update()
>   --some code
>   someVal = xPos * 10
>   --remaining code
> end
>
> The way I see it right now is I have to write the function
> like this:
>
> function myObj.update()
>    --some code
>    myObj.someVal = myObj.xPos * 10
>    --remaining code
> end

A few others have already given you good advice, but here's
a quick-and-dirty thing that you may or may not find
relevant or useful:

function myObj.update()
   local someVal, xPos = myObj.someVal, myObj.xPos -- Short names
   --some code
   someVal = xPos * 10
   --remaining code
   myObj.someVal, myObj.xPos = someVal, xPos -- Reassignment
      -- to long names -- wouldn't even be necessary if
      -- someVal and xPos themselves happened to be tables
      -- whose elements you were messing with.
end

-- 
Aaron Brown