[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Writing Iterator in C
- From: Ralph Hempel <rhempel@...>
- Date: Wed, 31 Dec 2008 10:51:30 -0500
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.
I guess I'll have to keep the function working the way it is
for now, which is OK, I guess.
Also odd is your use of brackets in Lua return statements. This is
invalid in vanilla Lua, and misleading if made valid, as a bracketed
expression normally produces exactly one value.
Sorry about that - as you might guess, that was not an actual
copy from the file, I retyped that part and got the C syntax
into my Lua expressions. The actual code does not have the brackets.
And yes, I know that I should have copied the actual file contents
instead of retyping, it was just faster, but in the end incorrect
to do it that way. Lesson learned.