[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: get_local() and "(for index/limit/stop)"
- From: "Tom Spilman" <tom@...>
- Date: Wed, 15 Sep 2004 17:58:15 -0500
> -----Original Message-----
> From: email@example.com
> [mailto:firstname.lastname@example.org] On Behalf Of
> Fabio Mascarenhas
> Sent: Wednesday, September 15, 2004 5:28 PM
> To: Lua list
> Subject: Re: get_local() and "(for index/limit/stop)"
> "x" is not deleted and reallocated, check the OP_FORLOOP
> implementation in lvm.c. :-)
Maybe I interpreted the behavior wrong then. When I step thru a for loop I
only get "x" while inside the loop. Specifically on each pass thru the loop
when it steps back to the for line the "x" is no longer returned by
get_local(). If "x" isn't deleted and there isn't some scoping issue I'm
not seeing then get_local() is wrong in this case.
> What Lua version are you using?
I'm using the first "5.1 (work)" release from a few months ago. Maybe this
is a change in 5.1?
> Lua 5.0.2 shows no "(for index)" local while debugging, and
> shows the loop index does show up as a local in the line of
> the for statement. Same for Lua 5.0. The Lua compiler does
> not even generate "(for index)" as a local.
Well this doesn't seem to be the case for a script executed within the "5.1
(work)" version of Lua.exe.
Looking thru the source in lparser.c fornum() does this...
new_localvarliteral(ls, "(for index)", 0);
new_localvarliteral(ls, "(for limit)", 1);
new_localvarliteral(ls, "(for step)", 2);
new_localvar(ls, varname, 3);
So it seems they made an explicit decision to not name "(for index)" with
the real index name. It would be nice if this was corrected so I can
clearly tell which nested loop these automatic for locals correspond to.
Co-owner | Programmer