[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Writing Iterator in C
- From: "Peter Cawley" <lua@...>
- Date: Wed, 31 Dec 2008 15:56:00 +0000
On Wed, Dec 31, 2008 at 3:51 PM, Ralph Hempel <rhempel@hempeldesigngroup.com> wrote:
Peter Cawley wrote:
Note that p (the control variable) is changed in the body
of the for loop, and this works fine in pure Lua.
Well, it shouldn't. Modifying the control variables of a for loop only affects the copy of that variable within the for loop body - not the variable which is passed back into the iteration function (similarly with a numeric for, the control variable is shadowed within the loop body).
That's what I thought reading the PiL manual, but I was not sure
so I tried it. I was a bit surprised that it worked too.
Except it doesn't work: http://codepad.org/MfGGdS56