[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Forward declarations in modules
- From: Nick Gammon <nick@...>
- Date: Fri, 8 Sep 2006 09:57:20 +1000
On 08/09/2006, at 9:14 AM, Jerome Vuarand wrote:
Here you can see that you have two and only two variable creations.
That's why you have two different printed values.
Yes I see what is happening, but the surprising thing is that local
variables behave so much differently to other types of variables.
eg.
a = 5 -- add to _G.a
a = 6 -- replace _G.a
however
local a = 5 -- make a local variable named a
local a = 6 -- make a completely different variable named a
The Lua book notes that "access to local variables is faster than to
global ones".
I would have to guess from this example that a local variable is,
effectively, a fixed piece of memory that involves no table lookups
(nor metatables), however access to global variables involves at
least one table lookup.
- Nick