[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: just a little question about the lua way :)
- From: Walter Cruz <walter.php@...>
- Date: Wed, 14 Dec 2005 11:28:25 -0300
I have a little doubt. I have a lua table with some values and I neet the sum of them.
Here's is the code snippet:
c = 0
c = c+v
result = 0
for _,value in values do
result = result + value
The code between result = 0 and print(result) works, but i don't think
that this is the 'lua way' of doing the things. Except by the lua way
The function sum is my attempt to make it more 'lua'. It works, but all
the values are printed and I have the c variable outside of the scope
of the function (global). As far I know, I can do it with a closure no ?
I just wanna make my lua code more lua :)
Thanks on advance.