[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: scope of local outside function
- From: "John Passaniti" <jmp@...>
- Date: Thu, 22 Jun 2000 14:19:59 -0400
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? 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?