lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> > Firstly, why can variables be local to the main chunk? As far as I can
> > see, there is no way to access them?
> 
> What do you mean? What about that?
> 
>   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
>

And if I drop the for-loop:

> local s = 0
> function f(x) return %s + x end
> f(1)
error: attempt to perform arithmetic on a nil value
stack traceback:
   1:  function `f' at line 1 [string "function f(x) return %s + x end"]
   2:  main of string "f(1)" at line 1
>

You see? The local value is ignored -- the global one is
used automatically.

If this isn't the way it is supposed to work, then
I'm happy (except that this is the way it *does*
work...)

The only modification I have made to my interpreter
is to incorporate your readline patch. That shouldn't
affect anything, should it?

--

  Magnus Lie Hetland      (magnus at hetland dot org)

 "Reality is what refuses to disappear when you stop
  believing in it"                 -- Philip K. Dick