[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: scope of local outside function
- From: David Jeske <jeske@...>
- Date: Thu, 22 Jun 2000 12:23:06 -0700
On Thu, Jun 22, 2000 at 03:29:30PM -0300, John Passaniti wrote:
> I'm confused. What's going on here? I typed the following into a file and
> ran it with the "lua" command:
>
> local x = 42
> print(x)
>
> The result was "42" was printed. Then I tried the same thing interactively
> from the keyboard, and the result this time was nil.
>
> The Lua documentation states that local variables may be declared anywhere
> inside a block. Since running the code from a file worked, does that imply
> files have a implicit block around them?
Yes, a file is a block.
> The second question is what happened to "x" in the interactive case.
> No error was reported by Lua, so I suppose it did what I told it.
> But since the value was nil when I printed it, where did "x" go and
> will whatever memory it allocated be reclaimed?
In the interactive mode, a line is a block.
Notice that if you want to declare a function in interactive mode, it
has to be all on one line.
--
David Jeske (N9LCA) + http://www.chat.net/~jeske/ + jeske@chat.net