[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Upvalue question
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Fri, 16 Feb 2001 10:46:34 -0200 (EDT)
>> local s = 0
>> for i=1,10000 do s=s+i end
>> function f(x) return %s + x end
>
>This doesn't work in my interpreter (4.0)
>
>Transcript:
>
>> local s = 0
>> for i=1,10000 do s=s+i end
>error: attempt to perform arithmetic on global `s' (a nil value)
>stack traceback:
> 1: main of string "for i=1,10000 do s=s+i end" at line 1
The 3 lines of code were supposed to be run in a file, not interactively.
When you run interactively, each line is a separate chunk and so 's' is
local in the first one, but global in the second one, hence the error.
--lhf