[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: startpc of locals
- From: Jamie Webb <j@...>
- Date: Thu, 23 Sep 2004 14:37:49 +0100
On Wed, Sep 22, 2004 at 11:10:46PM -0300, Hisham H. Muhammad wrote:
>
> Hi,
>
> I just noticed what I consider to be a slight misbehavior in the startpc field
> of local variable declarations. In test/fibfor.lua, we have
>
> local a,b = 1, 1
>
> which generates the following code:
> 1 [5] LOADK 0 -1 ; 1
> 2 [5] LOADK 1 -1 ; 1
>
> So far, so good. However, the value of startpc for both locals is 2.
I think the behaviour is correct. Locals are not in scope until after the
statement in which they are created. Locals declared in the same
statement are conceptually declared simultaneously. In particular, note:
x = 1
y = 2
local x, y = y, x
print(x, y)
-- Prints: 2 1
The value assigned to y is not the just-assigned x but the original
global x. The local x is not yet in scope at that point.
-- Jamie Webb